Avoid string concatentation in IngestDocument.FieldPath

Today, the constructor for IngestDocument#FieldPath does a string
concatentation and two object allocation on every field path. This
commit removes these unnecessary operations.

Relates #18108
This commit is contained in:
Jason Tedor 2016-05-03 10:05:44 -04:00
parent d01526b6ab
commit 85d2fc0e38
1 changed files with 8 additions and 4 deletions

View File

@ -51,6 +51,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
public final class IngestDocument { public final class IngestDocument {
public final static String INGEST_KEY = "_ingest"; public final static String INGEST_KEY = "_ingest";
private static final String INGEST_KEY_PREFIX = INGEST_KEY + ".";
private static final String SOURCE_PREFIX = SourceFieldMapper.NAME + ".";
static final String TIMESTAMP = "timestamp"; static final String TIMESTAMP = "timestamp";
@ -600,6 +602,7 @@ public final class IngestDocument {
} }
private class FieldPath { private class FieldPath {
private final String[] pathElements; private final String[] pathElements;
private final Object initialContext; private final Object initialContext;
@ -608,13 +611,13 @@ public final class IngestDocument {
throw new IllegalArgumentException("path cannot be null nor empty"); throw new IllegalArgumentException("path cannot be null nor empty");
} }
String newPath; String newPath;
if (path.startsWith(INGEST_KEY + ".")) { if (path.startsWith(INGEST_KEY_PREFIX)) {
initialContext = ingestMetadata; initialContext = ingestMetadata;
newPath = path.substring(8, path.length()); newPath = path.substring(INGEST_KEY_PREFIX.length(), path.length());
} else { } else {
initialContext = sourceAndMetadata; initialContext = sourceAndMetadata;
if (path.startsWith(SourceFieldMapper.NAME + ".")) { if (path.startsWith(SOURCE_PREFIX)) {
newPath = path.substring(8, path.length()); newPath = path.substring(SOURCE_PREFIX.length(), path.length());
} else { } else {
newPath = path; newPath = path;
} }
@ -624,5 +627,6 @@ public final class IngestDocument {
throw new IllegalArgumentException("path [" + path + "] is not valid"); throw new IllegalArgumentException("path [" + path + "] is not valid");
} }
} }
} }
} }