Apache Lucene open-source search software
Lazily allocate ByteArrayDataInputs in SegmentTermsEnumFrame (#15637)
Misha Dmitriev33120262c9a5
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 3975f2b70b6..b242f8e94b1 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -187,7 +187,7 @@ ImprovementsOptimizations----------------------(No changes)+* GITHUB#15637: Lazily allocate ByteArrayDataInputs in SegmentTermsEnumFrame#15637 (Misha Dmitriev)Bug Fixes---------------------diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnumFrame.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnumFrame.javaindex b55d9396886..dc3a53c334c 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnumFrame.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnumFrame.java@@ -46,14 +46,14 @@ final class SegmentTermsEnumFrame {long totalSuffixBytes; // for statsbyte[] suffixBytes;- final ByteArrayDataInput suffixesReader = new ByteArrayDataInput();+ ByteArrayDataInput suffixesReader;byte[] suffixLengthBytes;final ByteArrayDataInput suffixLengthsReader;byte[] statBytes;int statsSingletonRunLength = 0;- final ByteArrayDataInput statsReader = new ByteArrayDataInput();+ ByteArrayDataInput statsReader;long rewindPos;@@ -96,7 +96,7 @@ final class SegmentTermsEnumFrame {// metadata bufferbyte[] bytes;- final ByteArrayDataInput bytesReader = new ByteArrayDataInput();+ ByteArrayDataInput bytesReader;private final SegmentTermsEnum ste;@@ -200,7 +200,11 @@ final class SegmentTermsEnumFrame {throw new CorruptIndexException(e.getMessage(), ste.in, e);}compressionAlg.read(ste.in, suffixBytes, numSuffixBytes);- suffixesReader.reset(suffixBytes, 0, numSuffixBytes);+ if (suffixesReader == null) {+ suffixesReader = new ByteArrayDataInput(suffixBytes, 0, numSuffixBytes);+ } else {+ suffixesReader.reset(suffixBytes, 0, numSuffixBytes);+ }int numSuffixLengthBytes = ste.in.readVInt();allEqual = (numSuffixLengthBytes & 0x01) != 0;@@ -230,7 +234,11 @@ final class SegmentTermsEnumFrame {statBytes = new byte[ArrayUtil.oversize(numBytes, 1)];}ste.in.readBytes(statBytes, 0, numBytes);- statsReader.reset(statBytes, 0, numBytes);+ if (statsReader == null) {+ statsReader = new ByteArrayDataInput(statBytes, 0, numBytes);+ } else {+ statsReader.reset(statBytes, 0, numBytes);+ }statsSingletonRunLength = 0;metaDataUpto = 0;@@ -246,7 +254,11 @@ final class SegmentTermsEnumFrame {bytes = new byte[ArrayUtil.oversize(numBytes, 1)];}ste.in.readBytes(bytes, 0, numBytes);- bytesReader.reset(bytes, 0, numBytes);+ if (bytesReader == null) {+ bytesReader = new ByteArrayDataInput(bytes, 0, numBytes);+ } else {+ bytesReader.reset(bytes, 0, numBytes);+ }// Sub-blocks of a single floor block are always// written one after another -- tail recurse: