Keep the stored key when ContiguousMap's indexer updates a value - #75
Merged
Merged
Conversation
… [patch] The indexer setter rebuilt the entry from the caller's key, so with a normalising comparer an update through map["APPLE"] rewrote the key that Keys, enumeration and AsSpan() report, while keyToIndex still held the original. Keep the stored key and replace only the value, as Dictionary, InsertionOrderMap and OrderedMap do. Fixes #69 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXTjHR3MfJpmxt8LEwNkjm
|
matt-edmondson
deleted the
claude/containers-69-map-indexer-keeps-key
branch
September 26, 2026 23:49
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.



Fixes #69
When the key already existed,
ContiguousMap's indexer setter rebuilt the entry with the caller's key. With a normalising comparer,map["APPLE"] = 2aftermap["Apple"] = 1changed the key reported byKeys, enumeration andAsSpan()to"APPLE", whilekeyToIndexstill held"Apple".The setter now keeps the stored key and replaces only the value:
new Entry(items[index].Key, value).Dictionary<,>,InsertionOrderMapandOrderedMapalready behave this way.Tests
Indexer_SetExistingKeyWithDifferentSpelling_KeepsOriginalKey. It usesStringComparer.OrdinalIgnoreCaseand asserts thatKeys,AsSpan()and enumeration all still report"Apple"with value 2.Keys. With the fix it passes.Containers.Testsuite passes (390/390), and the Release build has no warnings.🤖 Generated with Claude Code
https://claude.ai/code/session_01YXTjHR3MfJpmxt8LEwNkjm
Generated by Claude Code