Skip to content

Commit d3c758b

Browse files
committed
perf: switches to lazy instantiation
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 339f61f commit d3c758b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public MapNode(ParsingContext context, JsonNode node) : base(
3333
}
3434

3535
_node = mapNode;
36+
_nodes = new (() => _node.Select(p => GetPropertyNodeFromJsonNode(p.Key, p.Value)).ToList(), true);
3637
}
3738

3839
public PropertyNode? this[string key]
@@ -130,11 +131,10 @@ public override Dictionary<string, HashSet<T>> CreateArrayMap<T>(Func<ValueNode,
130131
return nodes.ToDictionary(kvp => kvp.key, kvp => kvp.values);
131132
}
132133

133-
private List<PropertyNode>? _nodes;
134+
private readonly Lazy<List<PropertyNode>> _nodes;
134135
public IEnumerator<PropertyNode> GetEnumerator()
135136
{
136-
_nodes ??= _node.Select(p => GetPropertyNodeFromJsonNode(p.Key, p.Value)).ToList();
137-
return _nodes.GetEnumerator();
137+
return _nodes.Value.GetEnumerator();
138138
}
139139

140140
IEnumerator IEnumerable.GetEnumerator()

0 commit comments

Comments
 (0)