Skip to content

Commit a76f56b

Browse files
Move building fieldNames set to class constructor (#131722)
This patch moves building the set of fieldName prefixes in the FallbackSyntheticSourceBlockLoader to the constructor. This set does not change between invocations (since the fieldName is final), so we can just do the work once when constructing the BlockLoader instead of per-document.
1 parent b941518 commit a76f56b

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

server/src/main/java/org/elasticsearch/index/mapper/FallbackSyntheticSourceBlockLoader.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,16 @@ public SortedSetDocValues ordinals(LeafReaderContext context) throws IOException
7070
throw new UnsupportedOperationException();
7171
}
7272

73-
private record IgnoredSourceRowStrideReader<T>(String fieldName, Reader<T> reader) implements RowStrideReader {
74-
@Override
75-
public void read(int docId, StoredFields storedFields, Builder builder) throws IOException {
76-
var ignoredSource = storedFields.storedFields().get(IgnoredSourceFieldMapper.NAME);
77-
if (ignoredSource == null) {
78-
builder.appendNull();
79-
return;
80-
}
81-
82-
Map<String, List<IgnoredSourceFieldMapper.NameValue>> valuesForFieldAndParents = new HashMap<>();
83-
84-
// Contains name of the field and all its parents
85-
Set<String> fieldNames = new HashSet<>() {
73+
private static class IgnoredSourceRowStrideReader<T> implements RowStrideReader {
74+
// Contains name of the field and all its parents
75+
private final Set<String> fieldNames;
76+
private final String fieldName;
77+
private final Reader<T> reader;
78+
79+
IgnoredSourceRowStrideReader(String fieldName, Reader<T> reader) {
80+
this.fieldName = fieldName;
81+
this.reader = reader;
82+
this.fieldNames = new HashSet<>() {
8683
{
8784
add("_doc");
8885
}
@@ -97,6 +94,18 @@ public void read(int docId, StoredFields storedFields, Builder builder) throws I
9794
fieldNames.add(current.toString());
9895
}
9996

97+
}
98+
99+
@Override
100+
public void read(int docId, StoredFields storedFields, Builder builder) throws IOException {
101+
var ignoredSource = storedFields.storedFields().get(IgnoredSourceFieldMapper.NAME);
102+
if (ignoredSource == null) {
103+
builder.appendNull();
104+
return;
105+
}
106+
107+
Map<String, List<IgnoredSourceFieldMapper.NameValue>> valuesForFieldAndParents = new HashMap<>();
108+
100109
for (Object value : ignoredSource) {
101110
IgnoredSourceFieldMapper.NameValue nameValue = IgnoredSourceFieldMapper.decode(value);
102111
if (fieldNames.contains(nameValue.name())) {

0 commit comments

Comments
 (0)