Skip to content

Commit f21cce6

Browse files
committed
reduce number of setImmediateXContentParent(...) invocations
1 parent ab612ba commit f21cce6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,9 @@ private static void innerParseObject(DocumentParserContext context) throws IOExc
377377
}
378378
break;
379379
case START_OBJECT:
380-
context.setImmediateXContentParent(token);
381380
parseObject(context, currentFieldName);
382381
break;
383382
case START_ARRAY:
384-
context.setImmediateXContentParent(token);
385383
parseArray(context, currentFieldName);
386384
break;
387385
case VALUE_NULL:
@@ -524,6 +522,7 @@ private static void throwOnCopyToOnObject(Mapper mapper, List<String> copyToFiel
524522

525523
private static void parseObject(final DocumentParserContext context, String currentFieldName) throws IOException {
526524
assert currentFieldName != null;
525+
context.setImmediateXContentParent(context.parser().currentToken());
527526
Mapper objectMapper = context.getMapper(currentFieldName);
528527
if (objectMapper != null) {
529528
doParseObject(context, currentFieldName, objectMapper);
@@ -616,6 +615,8 @@ private static void throwOnCreateDynamicNestedViaCopyTo(Mapper dynamicObjectMapp
616615
}
617616

618617
private static void parseArray(DocumentParserContext context, String lastFieldName) throws IOException {
618+
var prev = context.getImmediateXContentParent();
619+
context.setImmediateXContentParent(context.parser().currentToken());
619620
Mapper mapper = getLeafMapper(context, lastFieldName);
620621
if (mapper != null) {
621622
// There is a concrete mapper for this field already. Need to check if the mapper
@@ -629,6 +630,7 @@ private static void parseArray(DocumentParserContext context, String lastFieldNa
629630
} else {
630631
parseArrayDynamic(context, lastFieldName);
631632
}
633+
context.setImmediateXContentParent(prev);
632634
}
633635

634636
private static void parseArrayDynamic(DocumentParserContext context, String currentFieldName) throws IOException {
@@ -748,15 +750,11 @@ private static void parseNonDynamicArray(
748750
int elements = 0;
749751
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
750752
if (token == XContentParser.Token.START_OBJECT) {
751-
context.setImmediateXContentParent(token);
752753
elements = 2;
753754
parseObject(context, lastFieldName);
754755
} else if (token == XContentParser.Token.START_ARRAY) {
755-
var prev = context.getImmediateXContentParent();
756-
context.setImmediateXContentParent(token);
757756
elements = 2;
758757
parseArray(context, lastFieldName);
759-
context.setImmediateXContentParent(prev);
760758
} else if (token == XContentParser.Token.VALUE_NULL) {
761759
elements++;
762760
parseNullValue(context, lastFieldName);
@@ -776,7 +774,6 @@ private static void parseNonDynamicArray(
776774
&& context.getRecordedSource() == false) {
777775
context.getOffSetContext().maybeRecordEmptyArray(mapper.getOffsetFieldName());
778776
}
779-
context.setImmediateXContentParent(token);
780777
if (elements <= 1 && canRemoveSingleLeafElement) {
781778
context.removeLastIgnoredField(fullPath);
782779
}

0 commit comments

Comments
 (0)