chore(sonar): prefer TryGetValue over ContainsKey+indexer (CA1854)
Applied via `dotnet format analyzers --diagnostics CA1854 --severity info`. Eliminates the duplicate hash lookup in the `if (d.ContainsKey(k)) d[k]++ else d[k] = 1` pattern. The fixer rewrites the conditional to `if (d.TryGetValue(k, out var value)) d[k] = ++value;` which is semantically identical but does the lookup once. 4 files touched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
f5d539b906
commit
81254c12f9
@@ -186,9 +186,9 @@ public class QueryCollectionAnalyzer
|
||||
var table = query.FromClause?.Clause?.Trim();
|
||||
if (!string.IsNullOrWhiteSpace(table))
|
||||
{
|
||||
if (tableUsage.ContainsKey(table))
|
||||
if (tableUsage.TryGetValue(table, out int value))
|
||||
{
|
||||
tableUsage[table]++;
|
||||
tableUsage[table] = ++value;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -221,9 +221,9 @@ public class QueryCollectionAnalyzer
|
||||
foreach (var col in columns)
|
||||
{
|
||||
var columnName = col.Trim();
|
||||
if (columnUsage.ContainsKey(columnName))
|
||||
if (columnUsage.TryGetValue(columnName, out int value))
|
||||
{
|
||||
columnUsage[columnName]++;
|
||||
columnUsage[columnName] = ++value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user