-
Notifications
You must be signed in to change notification settings - Fork 323
remove duplicate dictionary lookups #4000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,11 +251,10 @@ internal bool AppDomainUnload(string appDomainKey) | |
| // For each decrement, subtract from count, and delete if we reach 0. | ||
| lock (_appDomainKeyHash) | ||
| { | ||
| if (_appDomainKeyHash.ContainsKey(appDomainKey)) | ||
| if (_appDomainKeyHash.TryGetValue(appDomainKey, out int value)) | ||
| { | ||
| // Do nothing if AppDomain did not call Start! | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("<sc.SqlConnectionContainer.AppDomainUnload|DEP> _appDomainKeyHash contained AppDomainKey: '{0}'.", appDomainKey); | ||
| int value = _appDomainKeyHash[appDomainKey]; | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("SqlConnectionContainer.AppDomainUnload|DEP> _appDomainKeyHash for AppDomainKey: '{0}' count: '{1}'.", appDomainKey, value); | ||
| Debug.Assert(value > 0, "Why is value 0 or less?"); | ||
|
|
||
|
|
@@ -271,9 +270,9 @@ internal bool AppDomainUnload(string appDomainKey) | |
| Debug.Assert(0 == value, "We did not reach 0 at end of loop in AppDomainUnload!"); | ||
| Debug.Assert(!_appDomainKeyHash.ContainsKey(appDomainKey), "Key not removed after AppDomainUnload!"); | ||
|
|
||
| if (_appDomainKeyHash.ContainsKey(appDomainKey)) | ||
| if (_appDomainKeyHash.TryGetValue(appDomainKey, out int remainingCount)) | ||
| { | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("SqlConnectionContainer.AppDomainUnload|DEP|ERR> ERROR - after the Stop() loop, _appDomainKeyHash for AppDomainKey: '{0}' entry not removed from hash. Count: {1}'", appDomainKey, _appDomainKeyHash[appDomainKey]); | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("SqlConnectionContainer.AppDomainUnload|DEP|ERR> ERROR - after the Stop() loop, _appDomainKeyHash for AppDomainKey: '{0}' entry not removed from hash. Count: {1}'", appDomainKey, remainingCount); | ||
| } | ||
| } | ||
| else | ||
|
|
@@ -509,10 +508,11 @@ internal void IncrementStartCount(string appDomainKey, out bool appDomainStart) | |
| // For each increment, add to count, and create entry if not present. | ||
| lock (_appDomainKeyHash) | ||
| { | ||
| if (_appDomainKeyHash.ContainsKey(appDomainKey)) | ||
| if (_appDomainKeyHash.TryGetValue(appDomainKey, out int count)) | ||
| { | ||
| _appDomainKeyHash[appDomainKey] = _appDomainKeyHash[appDomainKey] + 1; | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("SqlConnectionContainer.IncrementStartCount|DEP> _appDomainKeyHash contained AppDomainKey: '{0}', incremented count: '{1}'.", appDomainKey, _appDomainKeyHash[appDomainKey]); | ||
| count++; | ||
| _appDomainKeyHash[appDomainKey] = count; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can eliminate the increment here:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would result in the incorrect count being logged below |
||
| SqlClientEventSource.Log.TryNotificationTraceEvent("SqlConnectionContainer.IncrementStartCount|DEP> _appDomainKeyHash contained AppDomainKey: '{0}', incremented count: '{1}'.", appDomainKey, count); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -1617,7 +1617,7 @@ private bool Start( | |
| { | ||
| if (!_sqlDependencyPerAppDomainDispatchers.ContainsKey(appDomainKey)) | ||
| { | ||
| _sqlDependencyPerAppDomainDispatchers[appDomainKey] = dispatcher; | ||
| _sqlDependencyPerAppDomainDispatchers.Add(appDomainKey, dispatcher); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TryAdd doesnt exist in net classic |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -1636,7 +1636,7 @@ private bool Start( | |
| SqlConnectionContainer container = null; | ||
| lock (_connectionContainers) | ||
| { | ||
| if (!_connectionContainers.ContainsKey(hashHelper)) | ||
| if (!_connectionContainers.TryGetValue(hashHelper, out container)) | ||
| { | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("<sc.SqlDependencyProcessDispatcher.Start|DEP> {0}, hashtable miss, creating new container.", ObjectID); | ||
| container = new SqlConnectionContainer(hashHelper, appDomainKey, useDefaults); | ||
|
|
@@ -1646,7 +1646,6 @@ private bool Start( | |
| } | ||
| else | ||
| { | ||
| container = _connectionContainers[hashHelper]; | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("<sc.SqlDependencyProcessDispatcher.Start|DEP> {0}, hashtable hit, container: {1}", ObjectID, container.ObjectID); | ||
| if (container.InErrorState) | ||
| { | ||
|
|
@@ -1712,9 +1711,8 @@ internal bool Stop( | |
|
|
||
| lock (_connectionContainers) | ||
| { | ||
| if (_connectionContainers.ContainsKey(hashHelper)) | ||
| if (_connectionContainers.TryGetValue(hashHelper, out SqlConnectionContainer container)) | ||
| { | ||
| SqlConnectionContainer container = _connectionContainers[hashHelper]; | ||
| SqlClientEventSource.Log.TryNotificationTraceEvent("<sc.SqlDependencyProcessDispatcher.Stop|DEP> {0}, hashtable hit, container: {1}", ObjectID, container.ObjectID); | ||
| server = container.Server; // Return server, database, and queue info for use by calling SqlDependency. | ||
| database = container.Database; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow 3 identical lookups under the same lock 😄