Skip to content

Commit 818414d

Browse files
committed
fix: uses the json node clone API to avoid unecessary allocs
1 parent cce2495 commit 818414d

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
using System.Text.Json;
54
using System.Text.Json.Nodes;
6-
using System.Text.Json.Serialization;
7-
using Microsoft.OpenApi.Any;
85

96
namespace Microsoft.OpenApi.Helpers
107
{
118
internal static class JsonNodeCloneHelper
129
{
13-
private static readonly JsonSerializerOptions options = new()
14-
{
15-
ReferenceHandler = ReferenceHandler.IgnoreCycles
16-
};
17-
1810
internal static JsonNode Clone(JsonNode value)
1911
{
20-
var jsonString = Serialize(value);
21-
if (string.IsNullOrEmpty(jsonString))
22-
{
23-
return null;
24-
}
25-
26-
var result = JsonSerializer.Deserialize<JsonNode>(jsonString, options);
27-
return result;
28-
}
29-
30-
private static string Serialize(object obj)
31-
{
32-
if (obj == null)
33-
{
34-
return null;
35-
}
36-
var result = JsonSerializer.Serialize(obj, options);
37-
return result;
12+
return value.DeepClone();
3813
}
3914
}
4015
}

0 commit comments

Comments
 (0)