Quick exit for non-zero slice buffers (#12812)

This commit is contained in:
Stefan Vodita 2023-12-08 17:41:58 +00:00 committed by GitHub
parent 18a6033a7e
commit 1c4c1c831d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -178,6 +178,8 @@ Improvements
* GITHUB#12870: Tighten synchronized loop in DirectoryTaxonomyReader#getOrdinal. (Stefan Vodita)
* GITHUB#12812: Avoid overflows and false negatives in int slice buffer filled-with-zeros assertion. (Stefan Vodita)
Optimizations
---------------------
(No changes)

View File

@ -179,6 +179,19 @@ public class MemoryIndex {
super(allocator);
}
/**
* For slices, buffers must be filled with zeros, so that we can find a slice's end based on a
* non-zero final value.
*/
private static boolean assertSliceBuffer(int[] buffer) {
for (int value : buffer) {
if (value != 0) {
return false;
}
}
return true;
}
/**
* Creates a new int slice with the given starting size and returns the slices offset in the
* pool.
@ -197,14 +210,6 @@ public class MemoryIndex {
return upto;
}
private static boolean assertSliceBuffer(int[] buffer) {
int count = 0;
for (int i = 0; i < buffer.length; i++) {
count += buffer[i]; // for slices the buffer must only have 0 values
}
return count == 0;
}
/** Allocates a new slice from the given offset */
private int allocSlice(final int[] slice, final int sliceOffset) {
final int level = slice[sliceOffset] & 15;