From 9d11c7a6c152d41411927482e8b7151be0df705a Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Wed, 18 Apr 2018 15:13:24 +0200 Subject: [PATCH] Remove extra copy in ScriptDocValues.Strings This commit removes a BytesRef copy introduced in #29567 and not required. Relates #29567 --- .../index/fielddata/ScriptDocValues.java | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java index 01f6bc192988c..3d07a0f87aa5e 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java @@ -631,28 +631,9 @@ public String get(int index) { return values[index].get().utf8ToString(); } - public BytesRef getBytesValue() { - if (size() > 0) { - /** - * We need to make a copy here because {@link BinaryScriptDocValues} might reuse the - * returned value and the same instance might be used to - * return values from multiple documents. - **/ - return values[0].toBytesRef(); - } else { - return null; - } - } - public String getValue() { - BytesRef value = getBytesValue(); - if (value == null) { - return null; - } else { - return value.utf8ToString(); - } + return count == 0 ? null : get(0); } - } public static final class BytesRefs extends BinaryScriptDocValues { @@ -672,10 +653,7 @@ public BytesRef get(int index) { } public BytesRef getValue() { - if (count == 0) { - return new BytesRef(); - } - return values[0].toBytesRef(); + return count == 0 ? new BytesRef() : get(0); } }