Skip to content

Commit a07ced1

Browse files
committed
Refactor to use TryGetValue instead of ContainsKey
Replaced redundant ContainsKey checks with TryGetValue in filter building and AddRecursive methods. This improves performance and readability by reducing dictionary lookups and streamlining key existence checks.
1 parent 4453766 commit a07ced1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

PxWeb/Code/Api2/DataSource/Cnmm/ItemSelectionResolverCnmm.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ private static Dictionary<string, ItemSelection> RemoveUnrootedEntries(Dictionar
103103

104104
foreach (var selection in lookupTable.Values)
105105
{
106-
if (filter.ContainsKey(selection.Menu))
106+
if (filter.TryGetValue(selection.Menu, out var selections))
107107
{
108-
filter[selection.Menu].Add(selection);
108+
selections.Add(selection);
109109
}
110110
else
111111
{
@@ -124,13 +124,11 @@ private static Dictionary<string, ItemSelection> RemoveUnrootedEntries(Dictionar
124124

125125
private static void AddRecursive(string item, Dictionary<string, ItemSelection> result, Dictionary<string, List<ItemSelection>> lookup)
126126
{
127-
if (!lookup.ContainsKey(item))
127+
if (!lookup.TryGetValue(item, out var selections))
128128
{
129129
return;
130130
}
131131

132-
var selections = lookup[item];
133-
134132
if (selections != null && selections.Count > 0)
135133
{
136134
foreach (var selection in selections)

0 commit comments

Comments
 (0)