Use growNoCopy when copying bytes in BytesRefBuilder (#13930)

This commit is contained in:
Ignacio Vera 2024-10-21 07:36:46 +02:00 committed by GitHub
parent 3983fa2c8d
commit 05e06e51ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -53,6 +53,8 @@ Optimizations
* GITHUB#13800: MaxScoreBulkScorer now recomputes scorer partitions when the
minimum competitive allows for a more favorable partitioning. (Adrien Grand)
* GITHUB#13930: Use growNoCopy when copying bytes in BytesRefBuilder. (Ignacio Vera)
Bug Fixes
---------------------
* GITHUB#13832: Fixed an issue where the DefaultPassageFormatter.format method did not format passages as intended

View File

@ -100,8 +100,10 @@ public class BytesRefBuilder {
* #clear()} and then {@link #append(byte[], int, int)}.
*/
public void copyBytes(byte[] b, int off, int len) {
clear();
append(b, off, len);
assert ref.offset == 0;
ref.length = len;
growNoCopy(len);
System.arraycopy(b, off, ref.bytes, 0, len);
}
/**
@ -109,8 +111,7 @@ public class BytesRefBuilder {
* #clear()} and then {@link #append(BytesRef)}.
*/
public void copyBytes(BytesRef ref) {
clear();
append(ref);
copyBytes(ref.bytes, ref.offset, ref.length);
}
/**
@ -118,8 +119,7 @@ public class BytesRefBuilder {
* #clear()} and then {@link #append(BytesRefBuilder)}.
*/
public void copyBytes(BytesRefBuilder builder) {
clear();
append(builder);
copyBytes(builder.get());
}
/**
@ -135,7 +135,7 @@ public class BytesRefBuilder {
* text.
*/
public void copyChars(CharSequence text, int off, int len) {
grow(UnicodeUtil.maxUTF8Length(len));
growNoCopy(UnicodeUtil.maxUTF8Length(len));
ref.length = UnicodeUtil.UTF16toUTF8(text, off, len, ref.bytes);
}
@ -144,7 +144,7 @@ public class BytesRefBuilder {
* text.
*/
public void copyChars(char[] text, int off, int len) {
grow(UnicodeUtil.maxUTF8Length(len));
growNoCopy(UnicodeUtil.maxUTF8Length(len));
ref.length = UnicodeUtil.UTF16toUTF8(text, off, len, ref.bytes);
}