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

This commit is contained in:
Ignacio Vera 2021-04-20 10:55:19 +02:00 committed by GitHub
parent e0436872c4
commit 5592d582b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 4 deletions

View File

@ -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);

View File

@ -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]);
}

View File

@ -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;