Apache Lucene open-source search software
Quick exit for non-zero slice buffers (#12812)
Stefan Vodita1c4c1c831def
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex f1987fbacd5..cf60620494b 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -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)diff --git a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.javaindex c66770fda5b..09a521c880d 100644--- a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java+++ b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java@@ -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;