Skip to content

src: improve TSList iteration and erase operations - #517

Merged
santigimeno merged 1 commit into
node-v24.x-nsolid-v6.xfrom
santi/improve_tslist
Aug 20, 2026
Merged

src: improve TSList iteration and erase operations#517
santigimeno merged 1 commit into
node-v24.x-nsolid-v6.xfrom
santi/improve_tslist

Conversation

@santigimeno

@santigimeno santigimeno commented Aug 20, 2026

Copy link
Copy Markdown
Member

Add a size-aware for_each overload to TSList so callbacks can observe the list size while iterating. Return the updated size from erase and extend coverage for object and pointer specializations.

Summary by CodeRabbit

  • New Features

    • Collection iteration callbacks now receive the current list size.
    • Removing an item now reports the number of elements remaining.
  • Tests

    • Added coverage for these behaviors across both standard and pointer-based collections.

@santigimeno
santigimeno requested a review from RafaelGSS August 20, 2026 11:58
@santigimeno santigimeno self-assigned this Aug 20, 2026
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0d444f76-ea37-4ff9-b454-55ecea78ffed

📥 Commits

Reviewing files that changed from the base of the PR and between fb15c84 and f472092.

📒 Files selected for processing (2)
  • src/nsolid/thread_safe.h
  • test/cctest/test_nsolid_thread_safe.cc

Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


Walkthrough

TSList now reports the current list size to for_each callbacks. Its erase methods return the remaining size. Tests cover value and pointer specializations, including pointer cleanup.

Changes

TSList size reporting

Layer / File(s) Summary
TSList API updates
src/nsolid/thread_safe.h
Value and pointer specializations pass the list size to for_each callbacks and return the remaining size from erase.
TSList behavior coverage
test/cctest/test_nsolid_thread_safe.cc
Tests verify callback sizes, visited values, erase results, iterator removal, and pointer cleanup for both specializations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to f4720

The PR adds localized TSList iteration and erase behavior with accompanying tests, and no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: rafaelgss

Poem

I hop through lists where counts now flow,
Callbacks learn the sizes they should know.
Erase leaves totals clear and bright,
Value and pointer paths test right.
— A rabbit, pleased with every bite 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main TSList iteration and erase changes described in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch santi/improve_tslist

Comment @coderabbitai help to get the list of available commands.

@ns-control-tower ns-control-tower left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Walkthrough

This PR extends the TSList template (both the object and pointer specializations) with a new for_each overload that passes the current list size to the callback, and changes erase to return the post-erase list size. The new size-aware for_each captures list_.size() once before iterating so every callback invocation sees a consistent snapshot. Tests cover both specializations for the new for_each and erase return-value behavior.

Changes

File(s) Summary
src/nsolid/thread_safe.h Added size-aware for_each overload and changed erase return type from void to size_t in both TSList<DataType> and TSList<DataType*> specializations
test/cctest/test_nsolid_thread_safe.cc Added four tests: ObjectForEachWithSize, ObjectEraseReturnsSize, PointerForEachWithSize, PointerEraseReturnsSize

Assessment

  • erase return-type change is backward-compatible. The sole production caller, TracerImpl::removeHook in nsolid_trace.cc:254 (trace_hook_list_.erase(it)), discards the return value, which is valid in C++ — no [[nodiscard]]/warn_unused_result attribute is set on erase. No other production code calls TSList::erase (the remaining .erase() calls in the codebase are on LRUMap/std::map types, not TSList).
  • for_each overload is additive and unambiguous. The new overload differs in arity from the existing one ((const DataType&, size_t) vs (const DataType&)), so overload resolution is clean. The test lambdas match each signature exactly.
  • Size snapshot is correct. current_size is captured before the loop, giving all callbacks a consistent view. The mutex is non-recursive (init(true)init(), not init_recursive()), so a callback that re-enters a TSList method would deadlock rather than corrupt state — consistent with the existing for_each behavior.
  • Tests are thorough and correct. Pointer tests properly manage memory (delete before erase, or save raw pointers before erase then delete). Edge cases (empty after all erases, size after each erase) are covered.

No blocking findings. No C++ compiler was available in the sandbox, but the change is a small, well-contained header template extension with comprehensive tests.

Verdict: APPROVE — clean, low-risk additive API extension with complete test coverage.

Add a size-aware for_each overload to TSList so callbacks can observe
the list size while iterating. Return the updated size from erase and
extend coverage for object and pointer specializations.

Signed-off-by: Santiago Gimeno <santiago.gimeno@gmail.com>
PR-URL: #517
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
@santigimeno
santigimeno force-pushed the santi/improve_tslist branch from f472092 to 92fa8c8 Compare August 20, 2026 21:04
@santigimeno
santigimeno merged commit 92fa8c8 into node-v24.x-nsolid-v6.x Aug 20, 2026
14 of 18 checks passed
@santigimeno
santigimeno deleted the santi/improve_tslist branch August 20, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants