Apache Lucene open-source search software
fixed length prefix for use with PagedBytes
Simon Willnauer0aa416f0cb4c
diff --git a/lucene/src/java/org/apache/lucene/index/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/values/Bytes.javaindex 691abe588bf..70343ca1eca 100644--- a/lucene/src/java/org/apache/lucene/index/values/Bytes.java+++ b/lucene/src/java/org/apache/lucene/index/values/Bytes.java@@ -243,7 +243,7 @@ public final class Bytes {if (initIndex)initIndexOut();}-+protected void initDataOut() throws IOException {datOut = dir.createOutput(IndexFileNames.segmentFileName(id, "",IndexFileNames.CSF_DATA_EXTENSION));diff --git a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.javaindex e07104f5d0e..beb0c14704c 100644--- a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java+++ b/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java@@ -24,6 +24,7 @@ import org.apache.lucene.index.values.Bytes.BytesBaseSource;import org.apache.lucene.index.values.Bytes.BytesReaderBase;import org.apache.lucene.index.values.Bytes.BytesWriterBase;import org.apache.lucene.index.values.FixedDerefBytesImpl.Reader.DerefBytesEnum;+import org.apache.lucene.store.DataOutput;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IndexInput;import org.apache.lucene.util.ArrayUtil;@@ -32,7 +33,6 @@ import org.apache.lucene.util.ByteBlockPool;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.BytesRefHash;import org.apache.lucene.util.CodecUtil;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.PagedBytes;import org.apache.lucene.util.RamUsageEstimator;import org.apache.lucene.util.ByteBlockPool.Allocator;@@ -113,7 +113,7 @@ class VarDerefBytesImpl {final int docAddress;if (e >= 0) {docAddress = array.array.address[e] = address;- address += IOUtils.writeLength(datOut, bytes);+ address += writePrefixLength(datOut, bytes);datOut.writeBytes(bytes.bytes, bytes.offset, bytes.length);address += bytes.length;} else {@@ -121,7 +121,18 @@ class VarDerefBytesImpl {}docToAddress[docID] = docAddress;}-++ private static int writePrefixLength(DataOutput datOut, BytesRef bytes) throws IOException{+ if (bytes.length < 128) {+ datOut.writeByte((byte) bytes.length);+ return 1;+ } else {+ datOut.writeByte((byte) (0x80 | (bytes.length >> 8)));+ datOut.writeByte((byte) (bytes.length & 0xff));+ return 2;+ }+ }+public long ramBytesUsed() {return bytesUsed.get();}@@ -216,15 +227,14 @@ class VarDerefBytesImpl {@Overrideprotected void fill(long address, BytesRef ref) throws IOException {- // TODO(simonw): use pages heredatIn.seek(fp + --address);final byte sizeByte = datIn.readByte();final int size;- if ((sizeByte & 0x80) == 0) {+ if ((sizeByte & 128) == 0) {// length is 1 bytesize = sizeByte;} else {- size = (sizeByte & 0x7f) + ((datIn.readByte() & 0xff) << 7);+ size = ((sizeByte & 0x7f)<<8) | ((datIn.readByte() & 0xff));}if(ref.bytes.length < size)ref.grow(size);diff --git a/lucene/src/java/org/apache/lucene/util/IOUtils.java b/lucene/src/java/org/apache/lucene/util/IOUtils.javaindex 43120dde1bd..40cde1b9095 100644--- a/lucene/src/java/org/apache/lucene/util/IOUtils.java+++ b/lucene/src/java/org/apache/lucene/util/IOUtils.java@@ -20,8 +20,6 @@ package org.apache.lucene.util;import java.io.Closeable;import java.io.IOException;-import org.apache.lucene.store.DataOutput;-/** @lucene.internal */public final class IOUtils {@@ -61,37 +59,10 @@ public final class IOUtils {}}- if (priorException != null)+ if (priorException != null) {throw priorException;- else if (firstIOE != null)+ } else if (firstIOE != null) {throw firstIOE;- }-- /**- * Writes the length of the {@link BytesRef} as either a one or two bytes to- * the {@link DataOutput} and returns the number of bytes used.- *- * @param datOut- * the output to write to- * @param bytes- * the length to write- * @return the length of the {@link BytesRef} as either a one or two bytes to- * the {@link DataOutput} and returns the number of bytes used.- * @throws IOException- * if datOut throws an {@link IOException}- */- public static int writeLength(DataOutput datOut, BytesRef bytes)- throws IOException {- final int length = bytes.length;- if (length < 128) {- // 1 byte to store length- datOut.writeByte((byte) length);- return 1;- } else {- // 2 byte to store length- datOut.writeByte((byte) (0x80 | (length & 0x7f)));- datOut.writeByte((byte) ((length >> 7) & 0xff));- return 2;}}}diff --git a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.javaindex e2f3a206256..fcac9640ef7 100644--- a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java+++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java@@ -273,7 +273,6 @@ public class TestDocValuesIndexing extends LuceneTestCase {bytesRef.length = b.length;bytesRef.offset = 0;}- //byte upto = 0;for (int i = 0; i < numValues; i++) {if (isNumeric) {@@ -324,7 +323,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {public void runTestIndexBytes(IndexWriterConfig cfg, boolean withDeletions)throws CorruptIndexException, LockObtainFailedException, IOException {- Directory d = newDirectory();+ final Directory d = newDirectory();IndexWriter w = new IndexWriter(d, cfg);final List<Values> byteVariantList = new ArrayList<Values>(BYTES);// run in random order to test if fill works correctly during merges@@ -389,7 +388,6 @@ public class TestDocValuesIndexing extends LuceneTestCase {assertEquals(base + numRemainingValues, r.numDocs());int v = 0;for (int i = base; i < r.numDocs(); i++) {-String msg = " field: " + byteIndexValue.name() + " at index: " + i+ " base: " + base + " numDocs:" + r.numDocs() + " bytesSize: "+ bytesSize;