Skip to content

Avoid double lookup in regex's HashtableExtensions#122892

Merged
stephentoub merged 1 commit intodotnet:mainfrom
stephentoub:doublehtlookup
Jan 5, 2026
Merged

Avoid double lookup in regex's HashtableExtensions#122892
stephentoub merged 1 commit intodotnet:mainfrom
stephentoub:doublehtlookup

Conversation

@stephentoub
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings January 5, 2026 19:10
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request optimizes the HashtableExtensions.TryGetValue method by eliminating a double lookup and specializing the generic method to work specifically with int values.

Key Changes

  • Replaced the generic TryGetValue<T> method with a non-generic version that returns int values
  • Changed the implementation from ContainsKey() + indexer (two lookups) to a single indexer access with pattern matching
  • Changed the default return value from default to explicit 0

@stephentoub stephentoub enabled auto-merge (squash) January 5, 2026 20:54
@stephentoub stephentoub merged commit 178bc48 into dotnet:main Jan 5, 2026
90 of 94 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants