From a17e92006f087a0601d9329bf9b9c946ca72478b Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 18 Oct 2016 16:07:52 +0200 Subject: [PATCH] LUCENE-7489: Wrap only once in case GCD compression is used. --- .../lucene70/Lucene70DocValuesProducer.java | 63 ++++++++----------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene70/Lucene70DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene70/Lucene70DocValuesProducer.java index 755da79ac86..637c8eef11f 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene70/Lucene70DocValuesProducer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene70/Lucene70DocValuesProducer.java @@ -424,47 +424,38 @@ final class Lucene70DocValuesProducer extends DocValuesProducer implements Close }; } else { final RandomAccessInput slice = data.randomAccessSlice(entry.valuesOffset, entry.valuesLength); - LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue); - if (entry.gcd != 1) { - values = applyGcd(values, entry.gcd); - } - if (entry.minValue != 0) { - values = applyDelta(values, entry.minValue); - } + final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue); if (entry.table != null) { - values = applyTable(values, entry.table); + final long[] table = entry.table; + return new LongValues() { + @Override + public long get(long index) { + return table[(int) values.get(index)]; + } + }; + } else if (entry.gcd != 1) { + final long gcd = entry.gcd; + final long minValue = entry.minValue; + return new LongValues() { + @Override + public long get(long index) { + return values.get(index) * gcd + minValue; + } + }; + } else if (entry.minValue != 0) { + final long minValue = entry.minValue; + return new LongValues() { + @Override + public long get(long index) { + return values.get(index) + minValue; + } + }; + } else { + return values; } - return values; } } - private LongValues applyDelta(LongValues values, long delta) { - return new LongValues() { - @Override - public long get(long index) { - return delta + values.get(index); - } - }; - } - - private LongValues applyGcd(LongValues values, long gcd) { - return new LongValues() { - @Override - public long get(long index) { - return values.get(index) * gcd; - } - }; - } - - private LongValues applyTable(LongValues values, long[] table) { - return new LongValues() { - @Override - public long get(long index) { - return table[(int) values.get(index)]; - } - }; - } - @Override public BinaryDocValues getBinary(FieldInfo field) throws IOException { BinaryEntry entry = binaries.get(field.name);