Skip to content

Improve DirtyFlagMap dirty flag correctness and mark Get() obsolete#2986

Merged
lahma merged 1 commit into
3.xfrom
fix/1417-dirtyflagmap-3x
Apr 3, 2026
Merged

Improve DirtyFlagMap dirty flag correctness and mark Get() obsolete#2986
lahma merged 1 commit into
3.xfrom
fix/1417-dirtyflagmap-3x

Conversation

@lahma

@lahma lahma commented Apr 3, 2026

Copy link
Copy Markdown
Member

Summary

Non-breaking improvements to DirtyFlagMap<TKey,TValue> from #1417:

  • Item 3: Add [MaybeNullWhen(false)] to TryGetValue out param (on NET8_0_OR_GREATER only, older TFMs lack the attribute on the interface)
  • Item 6: Indexer setter only sets dirty when value actually changes (uses EqualityComparer<TValue>.Default)
  • Items 14+15: Put() sets dirty after the operation (was a bug — dirty was set even when the subsequent operation threw on null key), and only when value differs
  • Item 16: PutAll benefits automatically from items 6+15, no code change needed
  • Item 4 prep: Get(TKey) marked [Obsolete], all 6 internal callers replaced with indexer access

What's NOT in this PR (breaking changes for main/4.x)

Items 1, 2, 4 (removal), 5, 7, 8, 10, 11, 12, 13, 14 (return type change) — these are all breaking API/behavior changes tracked separately.

Test plan

  • Updated 12 test assertions for dirty flag equality/null-key scenarios
  • Added 5 new PutAll dirty-flag tests
  • All 1114 unit tests pass on net10.0
  • Clean build across all TFMs (0 warnings, 0 errors)

Closes the non-breaking subset of #1417.

🤖 Generated with Claude Code

…1417)

- Add [MaybeNullWhen(false)] to TryGetValue out param (NET8_0_OR_GREATER)
- Only set dirty flag when indexer setter value actually changes
- Fix Put() to set dirty after operation, not before (bug: dirty was set
  even when subsequent operation threw)
- Only set dirty in Put() when value differs from current
- Mark Get(TKey) as [Obsolete] and replace all internal callers with indexer
- Add PutAll dirty-flag tests

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@sonarqubecloud

sonarqubecloud Bot commented Apr 3, 2026

Copy link
Copy Markdown

@lahma
lahma merged commit ded749d into 3.x Apr 3, 2026
15 checks passed
@lahma
lahma deleted the fix/1417-dirtyflagmap-3x branch April 3, 2026 08:13
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.

1 participant