Skip to content

Commit 6ce3214

Browse files
committed
perf: use deep equals for comparison to reduce allocations
Signed-off-by: Vincent Biret <[email protected]>
1 parent c5d9330 commit 6ce3214

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Microsoft.OpenApi/JsonNullSentinel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public static class JsonNullSentinel
3333
public static bool IsJsonNullSentinel(this JsonNode? node)
3434
{
3535
return node == SentinelJsonValue ||
36-
node is JsonValue jsonValue &&
37-
jsonValue.GetValueKind() == JsonValueKind.String &&
38-
jsonValue.TryGetValue<string>(out var value) &&
39-
SentinelValue.Equals(value, StringComparison.Ordinal);
36+
node is not null &&
37+
node.GetValueKind() == JsonValueKind.String &&
38+
// using deep equals here results in fewer allocations than TryGetValue
39+
JsonNode.DeepEquals(SentinelJsonValue, node);
4040
}
4141
}

0 commit comments

Comments
 (0)