Skip to content

Commit

Permalink
Do not create JsonMap.entries over and over again
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Jun 26, 2024
1 parent 01d5fc8 commit 4023661
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,23 @@ interface ValueExtractor {
class JsonMap extends AbstractMap<String, Object> implements NodeWrapper {
private final Node wrappedNode;

private Set<Entry<String, Object>> entrySet;

JsonMap(Node node) {
wrappedNode = node;
}

@NotNull
@Override
public Set<Entry<String, Object>> entrySet() {
Iterator<KeyValue> fields = wrappedNode.fields();
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(fields, 0), false)
.map(keyValue -> new SimpleEntry<>(
keyValue.getKey(), keyValue.getValue().getValue()))
.collect(Collectors.toSet());
if (entrySet == null) {
Iterator<KeyValue> fields = wrappedNode.fields();
entrySet = StreamSupport.stream(Spliterators.spliteratorUnknownSize(fields, 0), false)
.map(keyValue -> new SimpleEntry<>(
keyValue.getKey(), keyValue.getValue().getValue()))
.collect(Collectors.toSet());
}
return entrySet;
}

@Override
Expand Down

0 comments on commit 4023661

Please sign in to comment.