Skip to content

Commit

Permalink
Remove extra copy in ScriptDocValues.Strings
Browse files Browse the repository at this point in the history
This commit removes a BytesRef copy introduced in #29567 and not
required.

Relates #29567
  • Loading branch information
jimczi committed Apr 18, 2018
1 parent a548a7f commit 9d11c7a
Showing 1 changed file with 2 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BytesRef> {
Expand All @@ -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);
}

}
Expand Down

0 comments on commit 9d11c7a

Please sign in to comment.