From 37837133c357b1c2c6d284912947ed2c1784b790 Mon Sep 17 00:00:00 2001 From: panguixin Date: Tue, 14 May 2024 21:05:51 +0800 Subject: [PATCH] Remove unnecessary bit conversion for IndexSorter (#13320) --- .../org/apache/lucene/index/IndexSorter.java | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexSorter.java b/lucene/core/src/java/org/apache/lucene/index/IndexSorter.java index 10fc196232d..6db379b9b22 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexSorter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexSorter.java @@ -266,23 +266,16 @@ public interface IndexSorter { public ComparableProvider[] getComparableProviders(List readers) throws IOException { ComparableProvider[] providers = new ComparableProvider[readers.size()]; - final float missingValue; - if (this.missingValue != null) { - missingValue = this.missingValue; - } else { - missingValue = 0.0f; - } + final int missValueBits = Float.floatToIntBits(missingValue != null ? missingValue : 0.0f); for (int readerIndex = 0; readerIndex < readers.size(); readerIndex++) { final NumericDocValues values = valuesProvider.get(readers.get(readerIndex)); providers[readerIndex] = docID -> { - float value = missingValue; - if (values.advanceExact(docID)) { - value = Float.intBitsToFloat((int) values.longValue()); - } - return NumericUtils.floatToSortableInt(value); + final int valueBits = + values.advanceExact(docID) ? (int) values.longValue() : missValueBits; + return NumericUtils.sortableFloatBits(valueBits); }; } return providers; @@ -336,23 +329,17 @@ public interface IndexSorter { public ComparableProvider[] getComparableProviders(List readers) throws IOException { ComparableProvider[] providers = new ComparableProvider[readers.size()]; - final double missingValue; - if (this.missingValue != null) { - missingValue = this.missingValue; - } else { - missingValue = 0.0f; - } + final long missingValueBits = + Double.doubleToLongBits(missingValue != null ? missingValue : 0.0f); for (int readerIndex = 0; readerIndex < readers.size(); readerIndex++) { final NumericDocValues values = valuesProvider.get(readers.get(readerIndex)); providers[readerIndex] = docID -> { - double value = missingValue; - if (values.advanceExact(docID)) { - value = Double.longBitsToDouble(values.longValue()); - } - return NumericUtils.doubleToSortableLong(value); + final long valueBits = + values.advanceExact(docID) ? values.longValue() : missingValueBits; + return NumericUtils.sortableDoubleBits(valueBits); }; } return providers;