Skip to content

remove duplicate dictionary lookups#4000

Open
SimonCropp wants to merge 1 commit intodotnet:mainfrom
SimonCropp:remove-duplicate-dictionary-lookups
Open

remove duplicate dictionary lookups#4000
SimonCropp wants to merge 1 commit intodotnet:mainfrom
SimonCropp:remove-duplicate-dictionary-lookups

Conversation

@SimonCropp
Copy link
Contributor

@SimonCropp SimonCropp commented Mar 5, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 5, 2026 00:22
@SimonCropp SimonCropp requested a review from a team as a code owner March 5, 2026 00:22
@github-project-automation github-project-automation bot moved this to To triage in SqlClient Board Mar 5, 2026
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

Refactors several internal dictionary access patterns to avoid redundant ContainsKey + indexer lookups, primarily by switching to TryGetValue (and, for the DNS cache, direct indexer assignment) while preserving existing behavior in SqlDependency-related infrastructure.

Changes:

  • Replace double-lookups with TryGetValue in SqlDependency* code paths.
  • Simplify DNS cache insertion to a single overwrite assignment.
  • Update server enumerator parsing to use TryGetValue for instance detail extraction.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.cs Uses TryGetValue for dependency ID lookup under lock.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyListener.cs Replaces repeated dictionary lookups with TryGetValue in app-domain/container tracking paths.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs Uses TryGetValue to avoid multiple lookups in server/user hash management and default options composition.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SQLFallbackDNSCache.cs Simplifies add/replace semantics to a single assignment into the ConcurrentDictionary.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorManagedHelper.netcore.cs Uses TryGetValue when populating DataRow fields from parsed instance details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

2 participants