Skip to content

Commit

Permalink
Rollback the tmp storage of BytesRefHash to -1 after sort (#13014)
Browse files Browse the repository at this point in the history
  • Loading branch information
gf2121 committed Jan 25, 2024
1 parent 3a205fe commit d0098f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Expand Up @@ -214,6 +214,7 @@ protected void get(BytesRefBuilder builder, BytesRef result, int i) {
pool.fillBytesRef(result, bytesStart[compact[i]]);
}
}.sort(0, count);
Arrays.fill(compact, tmpOffset, compact.length, -1);
return compact;
}

Expand Down
18 changes: 11 additions & 7 deletions lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java
Expand Up @@ -176,13 +176,17 @@ public void testSort() {
hash.add(ref.get());
strings.add(str);
}
int[] sort = hash.sort();
assertTrue(strings.size() < sort.length);
int i = 0;
BytesRef scratch = new BytesRef();
for (String string : strings) {
ref.copyChars(string);
assertEquals(ref.get(), hash.get(sort[i++], scratch));
for (int iter = 0; iter < 3; iter++) {
// Test duplicate sort on a BytesRefHash instance work well. This makes no sense but some
// users need that.
int[] sort = hash.sort();
assertTrue(strings.size() < sort.length);
int i = 0;
BytesRef scratch = new BytesRef();
for (String string : strings) {
ref.copyChars(string);
assertEquals(ref.get(), hash.get(sort[i++], scratch));
}
}
hash.clear();
assertEquals(0, hash.size());
Expand Down

0 comments on commit d0098f8

Please sign in to comment.