Repository navigation
Add a ConcurrentStack DeepClone overload that keeps pop order [patch] - #112
Merged
Merged
Conversation
ConcurrentStack had no dedicated overload, so DeepClone bound to the IEnumerable overload and returned a top-first sequence; rebuilding a stack from it reversed the pop order. Clone from one ToArray snapshot, reversed, the same way the Stack overload does. Fixes #102 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW1vQbunMqKm6mgn4pF
|
This was referenced Oct 31, 2026
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.



ConcurrentStack<T>had no dedicated overload, sostack.DeepClone()bound to theIEnumerable<T>overload and returned the elements top-first. Rebuilding a stack from that sequence silently reversed the pop order.This adds
public static ConcurrentStack<T> DeepClone<T>(this ConcurrentStack<T> source):ToArray()snapshot, which is atomic forConcurrentStack, so the clone stays consistent while other threads push or pop.Stack<T>overload does.MakeGenericType, so it is safe under NativeAOT (Under NativeAOT, DeepClone over KeyValuePair elements with a value-type key or value throws TypeInitializationException (regression from #82) #92).IDE0305is suppressed on this method, with a justification. The analyzer wants a spread, but a spread would enumerate the stack instead of taking the atomic snapshot (see #100).The README's container table now lists the overload.
Validation:
ConcurrentStackCloneTestscheck the returned type, the pop order (3, 2, 1), element independence, and the empty case.Fixes #102
Generated by Claude Code