Index: src/test/org/apache/lucene/util/TestSortedVIntList.java =================================================================== --- src/test/org/apache/lucene/util/TestSortedVIntList.java (revision 901183) +++ src/test/org/apache/lucene/util/TestSortedVIntList.java (working copy) @@ -193,4 +193,11 @@ public void test12() { tstIllegalArgExc(new int[] {0,1,1,2,3,5,8,0}); } + public void test13Allocation() throws Exception { + int [] a = new int[2000]; // SortedVIntList initial byte size is 128 + for (int i = 0; i < a.length; i++) { + a[i] = (107 + i) * i; + } + tstIterator(new SortedVIntList(a), a); + } } Index: src/java/org/apache/lucene/store/IndexInput.java =================================================================== --- src/java/org/apache/lucene/store/IndexInput.java (revision 901183) +++ src/java/org/apache/lucene/store/IndexInput.java (working copy) @@ -21,6 +21,7 @@ import java.io.Closeable; import java.util.Map; import java.util.HashMap; +import org.apache.lucene.util.ArrayUtil; /** Abstract base class for input from a file in a {@link Directory}. A * random-access input stream. Used for all Lucene index input operations. @@ -122,16 +123,18 @@ if (preUTF8Strings) return readModifiedUTF8String(); int length = readVInt(); - if (bytes == null || length > bytes.length) - bytes = new byte[(int) (length*1.25)]; + if (bytes == null || length > bytes.length) { + bytes = new byte[ArrayUtil.getNextSize(length)]; + } readBytes(bytes, 0, length); return new String(bytes, 0, length, "UTF-8"); } private String readModifiedUTF8String() throws IOException { int length = readVInt(); - if (chars == null || length > chars.length) - chars = new char[length]; + if (chars == null || length > chars.length) { + chars = new char[ArrayUtil.getNextSize(length)]; + } readChars(chars, 0, length); return new String(chars, 0, length); } @@ -157,10 +160,11 @@ else if ((b & 0xE0) != 0xE0) { buffer[i] = (char)(((b & 0x1F) << 6) | (readByte() & 0x3F)); - } else + } else { buffer[i] = (char)(((b & 0x0F) << 12) | ((readByte() & 0x3F) << 6) | (readByte() & 0x3F)); + } } } @@ -181,10 +185,9 @@ byte b = readByte(); if ((b & 0x80) == 0){ //do nothing, we only need one byte - } - else if ((b & 0xE0) != 0xE0) { + } else if ((b & 0xE0) != 0xE0) { readByte();//read an additional byte - } else{ + } else { //read two additional bytes. readByte(); readByte(); Index: src/java/org/apache/lucene/util/SortedVIntList.java =================================================================== --- src/java/org/apache/lucene/util/SortedVIntList.java (revision 901183) +++ src/java/org/apache/lucene/util/SortedVIntList.java (working copy) @@ -128,8 +128,8 @@ } if ((lastBytePos + MAX_BYTES_PER_INT) > bytes.length) { - // biggest possible int does not fit - resizeBytes((bytes.length * 2) + MAX_BYTES_PER_INT); + // Biggest possible int does not fit. + resizeBytes(ArrayUtil.getNextSize(lastBytePos + MAX_BYTES_PER_INT)); } // See org.apache.lucene.store.IndexOutput.writeVInt()