Skip to content

Commit 9d11c7a

Browse files
committed
Remove extra copy in ScriptDocValues.Strings
This commit removes a BytesRef copy introduced in elastic#29567 and not required. Relates elastic#29567
1 parent a548a7f commit 9d11c7a

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java

+2-24
Original file line numberDiff line numberDiff line change
@@ -631,28 +631,9 @@ public String get(int index) {
631631
return values[index].get().utf8ToString();
632632
}
633633

634-
public BytesRef getBytesValue() {
635-
if (size() > 0) {
636-
/**
637-
* We need to make a copy here because {@link BinaryScriptDocValues} might reuse the
638-
* returned value and the same instance might be used to
639-
* return values from multiple documents.
640-
**/
641-
return values[0].toBytesRef();
642-
} else {
643-
return null;
644-
}
645-
}
646-
647634
public String getValue() {
648-
BytesRef value = getBytesValue();
649-
if (value == null) {
650-
return null;
651-
} else {
652-
return value.utf8ToString();
653-
}
635+
return count == 0 ? null : get(0);
654636
}
655-
656637
}
657638

658639
public static final class BytesRefs extends BinaryScriptDocValues<BytesRef> {
@@ -672,10 +653,7 @@ public BytesRef get(int index) {
672653
}
673654

674655
public BytesRef getValue() {
675-
if (count == 0) {
676-
return new BytesRef();
677-
}
678-
return values[0].toBytesRef();
656+
return count == 0 ? new BytesRef() : get(0);
679657
}
680658

681659
}

0 commit comments

Comments
 (0)