Fix BidirectionalMap leaving a stale reverse entry on key update#327403
Open
dsavy4 wants to merge 2 commits into
Open
Fix BidirectionalMap leaving a stale reverse entry on key update#327403dsavy4 wants to merge 2 commits into
dsavy4 wants to merge 2 commits into
Conversation
BidirectionalMap.set updated the forward map but never removed the
reverse mapping of the key's previous value. After map.set('a', 1)
followed by map.set('a', 2), a reverse lookup getKey(1) still returned
'a' even though 'a' now maps to 2.
Delete the previous value's reverse entry when an existing key is
reassigned. Added a regression test covering key updates.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes stale reverse mappings when a BidirectionalMap key is reassigned.
Changes:
- Removes the previous reverse entry before updating a key.
- Adds regression coverage for key reassignment.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/vs/base/common/map.ts |
Cleans up the old reverse mapping during updates. |
src/vs/base/test/common/map.test.ts |
Tests forward and reverse lookups after reassignment. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
BidirectionalMap.setupdates the forward map (_m1) and the reverse map (_m2), but when an existing key is reassigned it never removes the reverse entry for the key's previous value. That leaves a stale reverse mapping.Repro:
getKey(1)still resolves to'a'even though'a'now maps to2. This can surface wherever a key's value is updated, for example the marker decorations service (IMarkerto decoration id) when a marker's decoration id changes.The fix deletes the previous value's reverse entry when an existing key is reassigned. True one-to-one behavior is preserved, and a regression test covering key updates is added.