Skip to content

Commit 5592d58

Browse files
authored
LUCENE-9047: Adapt big endian dependent code to work in little endian
1 parent e043687 commit 5592d58

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/Lucene90CompressingStoredFieldsWriter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ static void writeZFloat(DataOutput out, float f) throws IOException {
361361
out.writeByte((byte) (0x80 | (1 + intVal)));
362362
} else if ((floatBits >>> 31) == 0) {
363363
// other positive floats: 4 bytes
364-
out.writeInt(floatBits);
364+
out.writeByte((byte) (floatBits >> 24));
365+
out.writeShort((short) (floatBits >>> 8));
366+
out.writeByte((byte) floatBits);
365367
} else {
366368
// other negative float: 5 bytes
367369
out.writeByte((byte) 0xFF);
@@ -399,7 +401,10 @@ static void writeZDouble(DataOutput out, double d) throws IOException {
399401
out.writeInt(Float.floatToIntBits((float) d));
400402
} else if ((doubleBits >>> 63) == 0) {
401403
// other positive doubles: 8 bytes
402-
out.writeLong(doubleBits);
404+
out.writeByte((byte) (doubleBits >> 56));
405+
out.writeInt((int) (doubleBits >>> 24));
406+
out.writeShort((short) (doubleBits >>> 8));
407+
out.writeByte((byte) (doubleBits));
403408
} else {
404409
// other negative doubles: 9 bytes
405410
out.writeByte((byte) 0xFF);

lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,29 @@ static void writeDocIds(int[] docIds, int start, int count, DataOutput out) thro
5050
}
5151
if (max <= 0xffffff) {
5252
out.writeByte((byte) 24);
53-
for (int i = 0; i < count; ++i) {
53+
// write them the same way we are reading them.
54+
int i;
55+
for (i = 0; i < count - 7; i += 8) {
56+
int doc1 = docIds[start + i];
57+
int doc2 = docIds[start + i + 1];
58+
int doc3 = docIds[start + i + 2];
59+
int doc4 = docIds[start + i + 3];
60+
int doc5 = docIds[start + i + 4];
61+
int doc6 = docIds[start + i + 5];
62+
int doc7 = docIds[start + i + 6];
63+
int doc8 = docIds[start + i + 7];
64+
long l1 = (doc1 & 0xffffffL) << 40 | (doc2 & 0xffffffL) << 16 | ((doc3 >>> 8) & 0xffffL);
65+
long l2 =
66+
(doc3 & 0xffL) << 56
67+
| (doc4 & 0xffffffL) << 32
68+
| (doc5 & 0xffffffL) << 8
69+
| ((doc6 >> 16) & 0xffL);
70+
long l3 = (doc6 & 0xffffL) << 48 | (doc7 & 0xffffffL) << 24 | (doc8 & 0xffffffL);
71+
out.writeLong(l1);
72+
out.writeLong(l2);
73+
out.writeLong(l3);
74+
}
75+
for (; i < count; ++i) {
5476
out.writeShort((short) (docIds[start + i] >>> 8));
5577
out.writeByte((byte) docIds[start + i]);
5678
}

lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ public void append(byte[] packedValue, int docID) throws IOException {
6262
+ "] but was ["
6363
+ packedValue.length
6464
+ "]";
65+
6566
out.writeBytes(packedValue, 0, packedValue.length);
66-
out.writeInt(docID);
67+
// write bytes for comparing in lexicographically order
68+
out.writeByte((byte) (docID >> 24));
69+
out.writeByte((byte) (docID >> 16));
70+
out.writeByte((byte) (docID >> 8));
71+
out.writeByte((byte) docID);
6772
count++;
6873
assert expectedCount == 0 || count <= expectedCount
6974
: "expectedCount=" + expectedCount + " vs count=" + count;

0 commit comments

Comments
 (0)