Skip to content

Apache Lucene open-source search software

LUCENE-9047: Adapt big endian dependent code to work in little endian

Ignacio Vera5592d582b856
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/Lucene90CompressingStoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/Lucene90CompressingStoredFieldsWriter.java
index 4b9cbe96ef0..937bd781516 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/Lucene90CompressingStoredFieldsWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/Lucene90CompressingStoredFieldsWriter.java
@@ -361,7 +361,9 @@ public final class Lucene90CompressingStoredFieldsWriter extends StoredFieldsWri
out.writeByte((byte) (0x80 | (1 + intVal)));
} else if ((floatBits >>> 31) == 0) {
// other positive floats: 4 bytes
- out.writeInt(floatBits);
+ out.writeByte((byte) (floatBits >> 24));
+ out.writeShort((short) (floatBits >>> 8));
+ out.writeByte((byte) floatBits);
} else {
// other negative float: 5 bytes
out.writeByte((byte) 0xFF);
@@ -399,7 +401,10 @@ public final class Lucene90CompressingStoredFieldsWriter extends StoredFieldsWri
out.writeInt(Float.floatToIntBits((float) d));
} else if ((doubleBits >>> 63) == 0) {
// other positive doubles: 8 bytes
- out.writeLong(doubleBits);
+ out.writeByte((byte) (doubleBits >> 56));
+ out.writeInt((int) (doubleBits >>> 24));
+ out.writeShort((short) (doubleBits >>> 8));
+ out.writeByte((byte) (doubleBits));
} else {
// other negative doubles: 9 bytes
out.writeByte((byte) 0xFF);
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
index a3fb5162220..6be3c43a1fa 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
@@ -50,7 +50,29 @@ class DocIdsWriter {
}
if (max <= 0xffffff) {
out.writeByte((byte) 24);
- for (int i = 0; i < count; ++i) {
+ // write them the same way we are reading them.
+ int i;
+ for (i = 0; i < count - 7; i += 8) {
+ int doc1 = docIds[start + i];
+ int doc2 = docIds[start + i + 1];
+ int doc3 = docIds[start + i + 2];
+ int doc4 = docIds[start + i + 3];
+ int doc5 = docIds[start + i + 4];
+ int doc6 = docIds[start + i + 5];
+ int doc7 = docIds[start + i + 6];
+ int doc8 = docIds[start + i + 7];
+ long l1 = (doc1 & 0xffffffL) << 40 | (doc2 & 0xffffffL) << 16 | ((doc3 >>> 8) & 0xffffL);
+ long l2 =
+ (doc3 & 0xffL) << 56
+ | (doc4 & 0xffffffL) << 32
+ | (doc5 & 0xffffffL) << 8
+ | ((doc6 >> 16) & 0xffL);
+ long l3 = (doc6 & 0xffffL) << 48 | (doc7 & 0xffffffL) << 24 | (doc8 & 0xffffffL);
+ out.writeLong(l1);
+ out.writeLong(l2);
+ out.writeLong(l3);
+ }
+ for (; i < count; ++i) {
out.writeShort((short) (docIds[start + i] >>> 8));
out.writeByte((byte) docIds[start + i]);
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
index 1087a4c94b4..fe26d37029b 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
@@ -62,8 +62,13 @@ public final class OfflinePointWriter implements PointWriter {
+ "] but was ["
+ packedValue.length
+ "]";
+
out.writeBytes(packedValue, 0, packedValue.length);
- out.writeInt(docID);
+ // write bytes for comparing in lexicographically order
+ out.writeByte((byte) (docID >> 24));
+ out.writeByte((byte) (docID >> 16));
+ out.writeByte((byte) (docID >> 8));
+ out.writeByte((byte) docID);
count++;
assert expectedCount == 0 || count <= expectedCount
: "expectedCount=" + expectedCount + " vs count=" + count;