Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/rime/candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,29 @@ class Candidate {
void set_end(size_t end) { end_ = end; }
void set_quality(double quality) { quality_ = quality; }

// per-candidate data
void set_data(const string& data_tag, an<void> datum = nullptr) {

Copilot AI Oct 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using void-erased pointers for arbitrary data is unsafe and forces consumers to manage casting/lifetimes. If feasible for the codebase standard, consider std::any (or an existing project-wide any/variant) for type-safe storage while still allowing arbitrary data.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any is safer but is not naturally nullable, and optional<any> seems to have too many overheads.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null pointers sounds like absence of record / deletion, as you compared it to optional<any>.

data_[data_tag] = datum;
}
an<void> get_data(const string& data_tag) const {
auto it = data_.find(data_tag);
return it != data_.end() ? it->second : nullptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another proof: null pointer and absence are equal.

}
vector<string> get_data_keys() const {
vector<string> keys;
Comment thread
ksqsf marked this conversation as resolved.
keys.reserve(data_.size());
for (const auto& pair : data_) {
keys.push_back(pair.first);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check non-null?

Null pointers should be treated as absent.

}
return keys;
}
Comment on lines +44 to +59

Copilot AI Oct 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new public APIs need clear documentation: ownership semantics of the stored pointers (who creates/destroys), expected type-erasure/casting pattern, whether nullptr is a supported value, thread-safety guarantees, and that get_data_keys returns keys in unspecified order. Please add brief doc comments for each method and the data_ member describing these behaviors.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is not a rime tradition ;-)


private:
string type_;
size_t start_ = 0;
size_t end_ = 0;
double quality_ = 0.;
hash_map<string, an<void>> data_;
};

using CandidateQueue = list<of<Candidate>>;
Expand Down
Loading