Repository navigation
fix: throw when a RingBuffer is modified during enumeration [patch] - #100
Merged
Merged
Conversation
RingBuffer was the last container whose enumerator did not fail fast. On a full buffer PushBack shifts every logical index, so pushing inside a foreach silently skipped an element, and Resample or Resize repeated or dropped elements without any error. Add a version field bumped by PushBack, Clear and AllocateBuffer (which covers Resize and Resample), and check it through Enumeration.ThrowIfModified the same way ContiguousCollection does. Fixes #86 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UoSUYMQMykgfsb5y6AhnKb
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
After #70 / #84,
RingBuffer<T>was the only container whose enumerator did not fail fast. On a full buffer, callingPushBackinside aforeachshifts every logical index, so the loop silently skipped an element. CallingResampleorResizemid-loop also corrupted the enumeration without raising an error.This follows the
ContiguousCollectionpattern:versionfield, incremented inPushBack,ClearandAllocateBuffer.AllocateBuffercovers bothResizeandResample.GetEnumerator()now returnsEnumerate(version), which callsEnumeration.ThrowIfModifiedbefore each yield and once after the loop.Tests
foreachthrowsInvalidOperationExceptionfor each mutator:PushBack,Clear,ResizeandResample.MoveNext.This PR is independent of #99 (#85, eviction leak). Both touch
PushBackbut in different lines, so they merge cleanly in either order.Fixes #86
🤖 Generated with Claude Code
https://claude.ai/code/session_01UoSUYMQMykgfsb5y6AhnKb
Generated by Claude Code