Skip to content

Commit 0084f4f

Browse files
committed
Revert SWAR optimization.
1 parent 5792d35 commit 0084f4f

File tree

2 files changed

+0
-96
lines changed

2 files changed

+0
-96
lines changed

bson/src/main/org/bson/io/ByteBufferBsonInput.java

-25
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.nio.charset.StandardCharsets;
2525

2626
import static java.lang.String.format;
27-
import static org.bson.internal.PlatformUtil.isUnalignedAccessAllowed;
2827

2928
/**
3029
* An implementation of {@code BsonInput} that is backed by a {@code ByteBuf}.
@@ -34,7 +33,6 @@
3433
public class ByteBufferBsonInput implements BsonInput {
3534

3635
private static final String[] ONE_BYTE_ASCII_STRINGS = new String[Byte.MAX_VALUE + 1];
37-
private static final boolean UNALIGNED_ACCESS_SUPPORTED = isUnalignedAccessAllowed();
3836
/* A dynamically sized scratch buffer, that is reused across BSON String reads:
3937
* 1. Reduces garbage collection by avoiding new byte array creation.
4038
* 2. Improves cache utilization through temporal locality.
@@ -184,34 +182,11 @@ public void skipCString() {
184182
buffer.position(pos + length);
185183
}
186184

187-
/*
188-
This method uses the SWAR (SIMD Within A Register) technique when aligned access is supported.
189-
SWAR finds a null terminator by processing 8 bytes at once.
190-
*/
191185
public int computeCStringLength(final int prevPos) {
192186
ensureOpen();
193187
int pos = buffer.position();
194188
int limit = buffer.limit();
195189

196-
if (UNALIGNED_ACCESS_SUPPORTED) {
197-
int chunks = (limit - pos) >>> 3;
198-
// Process 8 bytes at a time.
199-
for (int i = 0; i < chunks; i++) {
200-
long word = buffer.getLong(pos);
201-
long mask = word - 0x0101010101010101L;
202-
mask &= ~word;
203-
mask &= 0x8080808080808080L;
204-
if (mask != 0) {
205-
// first null terminator found in the Little Endian long
206-
int offset = Long.numberOfTrailingZeros(mask) >>> 3;
207-
// Found the null at pos + offset; reset buffer's position.
208-
return (pos - prevPos) + offset + 1;
209-
}
210-
pos += 8;
211-
}
212-
}
213-
214-
// Process remaining bytes one-by-one.
215190
while (pos < limit) {
216191
if (buffer.get(pos++) == 0) {
217192
return (pos - prevPos);

bson/src/test/unit/org/bson/internal/PlatformUtilTest.java

-71
This file was deleted.

0 commit comments

Comments
 (0)