Skip to content

Commit b71fa3f

Browse files
committed
Save a rehash and some traversals
1 parent e09fa14 commit b71fa3f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

modules/ingest-ecs/src/main/java/org/elasticsearch/ingest/ecs/EcsNamespaceProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.elasticsearch.cluster.metadata.ProjectId;
1313
import org.elasticsearch.common.util.Maps;
14-
import org.elasticsearch.common.util.set.Sets;
1514
import org.elasticsearch.ingest.AbstractProcessor;
1615
import org.elasticsearch.ingest.IngestDocument;
1716
import org.elasticsearch.ingest.Processor;
@@ -131,17 +130,20 @@ public IngestDocument execute(IngestDocument document) {
131130
renameSpecialKeys(document);
132131

133132
// Iterate through all top level keys and move them to the appropriate namespace
134-
for (String key : Sets.newHashSet(source.keySet())) {
133+
final var sourceItr = source.entrySet().iterator();
134+
while (sourceItr.hasNext()) {
135+
final var entry = sourceItr.next();
136+
final var key = entry.getKey();
137+
final var value = entry.getValue();
135138
if (KEEP_KEYS.contains(key)) {
136139
continue;
137140
}
138141
if (shouldMoveToResourceAttributes(key)) {
139-
Object value = source.remove(key);
140142
newResourceAttributes.put(key, value);
141143
} else {
142-
Object value = source.remove(key);
143144
newAttributes.put(key, value);
144145
}
146+
sourceItr.remove();
145147
}
146148

147149
// Flatten attributes

0 commit comments

Comments
 (0)