Skip to content

Commit a5a4c03

Browse files
committed
remove some duplicate dictionary lookups
1 parent 170ee50 commit a5a4c03

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ public bool HasOperations(string label)
5959
{
6060
Utils.CheckArgumentNullOrEmpty(label, nameof(label));
6161

62-
if (!(PathItems?.ContainsKey(label) ?? false))
62+
if (PathItems == null)
6363
{
6464
return false;
6565
}
6666

67-
return PathItems[label].Operations?.Any() ?? false;
67+
if (PathItems.TryGetValue(label, out var item))
68+
{
69+
return item.Operations?.Any() ?? false;
70+
}
71+
72+
return false;
6873
}
6974

7075
/// <summary>
@@ -190,14 +195,15 @@ private OpenApiUrlTreeNode Attach(IEnumerable<string> segments,
190195
}
191196

192197
// If the child segment has already been defined, then insert into it
193-
if (Children.ContainsKey(segment))
198+
if (Children.TryGetValue(segment, out var child))
194199
{
195200
var newPath = currentPath + PathSeparator + segment;
196201

197-
return Children[segment].Attach(segments: segments.Skip(1),
198-
pathItem: pathItem,
199-
label: label,
200-
currentPath: newPath);
202+
return child.Attach(
203+
segments: segments.Skip(1),
204+
pathItem: pathItem,
205+
label: label,
206+
currentPath: newPath);
201207
}
202208
else
203209
{
@@ -227,14 +233,7 @@ public void AddAdditionalData(Dictionary<string, List<string>> additionalData)
227233

228234
foreach (var item in additionalData)
229235
{
230-
if (AdditionalData.ContainsKey(item.Key))
231-
{
232-
AdditionalData[item.Key] = item.Value;
233-
}
234-
else
235-
{
236-
AdditionalData.Add(item.Key, item.Value);
237-
}
236+
AdditionalData[item.Key] = item.Value;
238237
}
239238
}
240239

0 commit comments

Comments
 (0)