-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Update ring buffer enhancement based on review feedback #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
- Updated operator== to compare source and index (not count) - Updated operator!= using De Morgan's law - Modified operator++ to set index to sentinel value N when reaching end - Changed end() and cend() to use index N instead of head_ - This provides proper iterator semantics where iterators are equal if they point to the same position in the same buffer Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com>
- Changed pre-increment expression to clearer form: (index_ + 1) % N - Enhanced comment to clarify sentinel value purpose Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com>
Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com>
|
你错误的提交了 _codeql_build_dir 目录 @copilot |
- Removed _codeql_build_dir directory (build artifacts) - Removed _codeql_detected_source_root file - Added CodeQL artifacts to .gitignore to prevent future commits Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com>
|
@copilot 你需要合并下improvement 分支的新的commit |
The improvement branch has already been merged into this branch in commit d06bf03. The current branch is up to date with all commits from improvement. |
| self_type& operator++() noexcept { | ||
| ++index_; | ||
| ++count_; | ||
| if (count_ >= source_->size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果你这样实现,那么上面的 [[nodiscard]] reference operator*() noexcept {
return (source_)[index_ % N];
}
template<bool Z = C, typename std::enable_if<(Z), int>::type = nullptr>
[[nodiscard]] const_reference operator*() const noexcept {
return (source_)[index_ % N];
}
template<bool Z = C, typename std::enable_if<(!Z), int>::type = nullptr>
[[nodiscard]] pointer operator->() noexcept {
return &((source_)[index_ % N]);
}
template<bool Z = C, typename std::enable_if<(Z), int>::type = nullptr>
[[nodiscard]] const_pointer operator->() const noexcept {
return &((*source_)[index_ % N]);
}是不是就多余%N了 @copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right! Fixed in bd7f23a. Since the operator++ keeps index_ in [0, N-1] during valid iteration and only sets it to N when reaching end, the % N in the dereference operators was redundant. I've also updated end() and cend() to consistently use N as the sentinel value.
- Removed % N from operator* and operator-> since index_ is always in [0, N-1] for valid iterators - Changed end() and cend() to use N as sentinel value, consistent with operator++ implementation - With the current operator++ that keeps index_ bounded and sets it to N at end, the modulo in dereference operators is redundant Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to bd7f23a in 1 minute and 18 seconds. Click for details.
- Reviewed
51lines of code in1files - Skipped
1files when reviewing. - Skipped posting
3draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. RingBuffer.hpp:51
- Draft comment:
Removed redundant modulo operations in operator* and operator->. Ensure that index_ is always normalized so that direct indexing (without modulo) is safe. - Reason this comment was not posted:
Comment looked like it was already resolved.
2. RingBuffer.hpp:66
- Draft comment:
The iterator pre-increment now uses count_ and sets index_ to N as a sentinel when the end is reached. Document that the sentinel value must not be dereferenced and that iterator validity assumes no container modification. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%This comment is purely informative, explaining the changes made to the iterator pre-increment logic. It does not provide a suggestion, ask for confirmation, or point out a potential issue. It seems to be a description of the code changes, which violates the rule against purely informative comments.
3. RingBuffer.hpp:218
- Draft comment:
End() and cend() now construct iterators with a sentinel index (N) instead of computing tail_ + size_. Ensure this design choice is clearly documented so that equality comparisons rely solely on the source and index. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =40%<= threshold50%The comment is suggesting that a design choice should be documented. It doesn't ask for confirmation of intention or testing, but it does imply that the documentation should be updated. This is a borderline case, but it seems to be more informative than actionable.
Workflow ID: wflow_HvcPWWOeY0iiR0en
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd7f23ad4c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| [[nodiscard]] iterator begin() noexcept { return iterator{this, tail_, 0};} | ||
| // Iterator to one past newest element. | ||
| [[nodiscard]] iterator end() noexcept { return iterator{this, tail_ + size_, size_};} | ||
| [[nodiscard]] iterator end() noexcept { return iterator{this, N, size_};} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make begin() equal end() for empty buffers
With end() now returning an iterator at index N, an empty buffer (size_ == 0) produces begin() at tail_ (typically 0) and end() at N. Because iterator equality only compares source() and index(), begin() != end() for empty buffers, so range-based for/for(it!=end) loops will perform one dereference of uninitialized storage. This is a regression from the prior end() definition (tail_ + size_) where empty buffers produced matching iterators. Consider returning end() from begin() when size_ == 0, or otherwise aligning the sentinel/index comparison so empty buffers don’t iterate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the ring buffer iterator implementation based on review feedback. It introduces a sentinel value approach for end iterators and removes modulo operations from dereference operators.
Changes:
- Iterator increment logic now uses a sentinel value (N) for end iterators instead of wrapping indices
- End iterators (end() and cend()) now use N as the index instead of tail_ + size_
- Modulo operations removed from operator*, operator->, which were previously needed for index wrapping
- Duplicate .gitignore entries added for CodeQL build artifacts
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| RingBuffer.hpp | Modified iterator increment logic to use sentinel values and removed modulo operations from dereference operators; updated end() iterators to use sentinel index |
| .gitignore | Added duplicate entries for CodeQL build artifacts (already present on lines 6-7) |
| template<bool Z = C, typename std::enable_if<(!Z), int>::type* = nullptr> | ||
| [[nodiscard]] reference operator*() noexcept { | ||
| return (*source_)[index_ % N]; | ||
| return (*source_)[index_]; |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the modulo operation from the dereference operator creates a critical bug. When an iterator has index_ set to the sentinel value N (which happens for end() iterators), dereferencing will access (*source_)[N], which is out of bounds. The valid range is [0, N-1].
While dereferencing end() iterators is undefined behavior in standard iterators, the previous implementation would not cause out-of-bounds access. Consider restoring the modulo operation to maintain memory safety, or add bounds checking to prevent accessing index N.
| template<bool Z = C, typename std::enable_if<(Z), int>::type* = nullptr> | ||
| [[nodiscard]] const_reference operator*() const noexcept { | ||
| return (*source_)[index_ % N]; | ||
| return (*source_)[index_]; |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the modulo operation from the dereference operator creates a critical bug. When an iterator has index_ set to the sentinel value N (which happens for end() iterators), dereferencing will access (*source_)[N], which is out of bounds. The valid range is [0, N-1].
While dereferencing end() iterators is undefined behavior in standard iterators, the previous implementation would not cause out-of-bounds access. Consider restoring the modulo operation to maintain memory safety, or add bounds checking to prevent accessing index N.
| template<bool Z = C, typename std::enable_if<(!Z), int>::type* = nullptr> | ||
| [[nodiscard]] pointer operator->() noexcept { | ||
| return &((*source_)[index_ % N]); | ||
| return &((*source_)[index_]); |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the modulo operation from the arrow operator creates a critical bug. When an iterator has index_ set to the sentinel value N (which happens for end() iterators), dereferencing will access (*source_)[N], which is out of bounds. The valid range is [0, N-1].
While dereferencing end() iterators is undefined behavior in standard iterators, the previous implementation would not cause out-of-bounds access. Consider restoring the modulo operation to maintain memory safety, or add bounds checking to prevent accessing index N.
| template<bool Z = C, typename std::enable_if<(Z), int>::type* = nullptr> | ||
| [[nodiscard]] const_pointer operator->() const noexcept { | ||
| return &((*source_)[index_ % N]); | ||
| return &((*source_)[index_]); |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the modulo operation from the arrow operator creates a critical bug. When an iterator has index_ set to the sentinel value N (which happens for end() iterators), dereferencing will access (*source_)[N], which is out of bounds. The valid range is [0, N-1].
While dereferencing end() iterators is undefined behavior in standard iterators, the previous implementation would not cause out-of-bounds access. Consider restoring the modulo operation to maintain memory safety, or add bounds checking to prevent accessing index N.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Important
Enhance
ring_buffer_iteratorinRingBuffer.hppby refining iterator behavior, equality operators, and removing redundant operations.operator++()inring_buffer_iteratorto setindex_to sentinel valueNwhen reaching end, instead of incrementingindex_.end()andcend()inring_bufferto use sentinel index valueN.operator==andoperator!=inring_buffer_iteratorto compare onlysource_andindex_, notcount_.operator*()andoperator->()inring_buffer_iterator.This description was created by
for bd7f23a. You can customize this summary. It will automatically update as commits are pushed.