Skip to content

Commit 0f68120

Browse files
authored
Merge pull request #1380 from SimonCropp/remove-some-duplicate-dictionary-lookups
remove some duplicate dictionary lookups
2 parents f30d451 + 3d8c66f commit 0f68120

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ public bool HasOperations(string label)
5858
{
5959
Utils.CheckArgumentNullOrEmpty(label, nameof(label));
6060

61-
if (!(PathItems?.ContainsKey(label) ?? false))
62-
{
63-
return false;
64-
}
65-
66-
return PathItems[label].Operations?.Any() ?? false;
61+
return PathItems is not null && PathItems.TryGetValue(label, out var item) && item.Operations is not null && item.Operations.Any();
6762
}
6863

6964
/// <summary>
@@ -189,14 +184,15 @@ private OpenApiUrlTreeNode Attach(IEnumerable<string> segments,
189184
}
190185

191186
// If the child segment has already been defined, then insert into it
192-
if (Children.ContainsKey(segment))
187+
if (Children.TryGetValue(segment, out var child))
193188
{
194189
var newPath = currentPath + PathSeparator + segment;
195190

196-
return Children[segment].Attach(segments: segments.Skip(1),
197-
pathItem: pathItem,
198-
label: label,
199-
currentPath: newPath);
191+
return child.Attach(
192+
segments: segments.Skip(1),
193+
pathItem: pathItem,
194+
label: label,
195+
currentPath: newPath);
200196
}
201197
else
202198
{
@@ -226,14 +222,7 @@ public void AddAdditionalData(Dictionary<string, List<string>> additionalData)
226222

227223
foreach (var item in additionalData)
228224
{
229-
if (AdditionalData.ContainsKey(item.Key))
230-
{
231-
AdditionalData[item.Key] = item.Value;
232-
}
233-
else
234-
{
235-
AdditionalData.Add(item.Key, item.Value);
236-
}
225+
AdditionalData[item.Key] = item.Value;
237226
}
238227
}
239228

0 commit comments

Comments
 (0)