Skip to content

Commit

Permalink
Optimize XContent Object Parsers (#78813)
Browse files Browse the repository at this point in the history
Optimize object parsers a little by extracting cold paths, removing some unnecessary
lambda wrapping and some other small things.
Also, fixed a very expensive use of these APIs in Phase moving from a very hot stream
instantiation to a standard loop.
  • Loading branch information
original-brownbear committed Oct 21, 2021
1 parent 72dcdb1 commit 0e8a00b
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public <T> void declareField(BiConsumer<Value, T> consumer, CheckedFunction<XCon
}

public <T> void declareObject(BiConsumer<Value, T> consumer, ContextParser<Context, T> objectParser, ParseField field) {
declareField(consumer, (p, c) -> objectParser.parse(p, c), field, ValueType.OBJECT);
declareField(consumer, objectParser, field, ValueType.OBJECT);
}

/**
Expand Down Expand Up @@ -240,7 +240,7 @@ public void declareBoolean(BiConsumer<Value, Boolean> consumer, ParseField field
}

public <T> void declareObjectArray(BiConsumer<Value, List<T>> consumer, ContextParser<Context, T> objectParser, ParseField field) {
declareFieldArray(consumer, (p, c) -> objectParser.parse(p, c), field, ValueType.OBJECT_ARRAY);
declareFieldArray(consumer, objectParser, field, ValueType.OBJECT_ARRAY);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ private class Target {
/**
* The parse context that is used for this invocation. Stored here so that it can be passed to the {@link #builder}.
*/
private Context context;
private final Context context;

/**
* How many of the constructor parameters have we collected? We keep track of this so we don't have to count the
Expand Down

0 comments on commit 0e8a00b

Please sign in to comment.