|
24 | 24 | import java.nio.charset.StandardCharsets;
|
25 | 25 |
|
26 | 26 | import static java.lang.String.format;
|
27 |
| -import static org.bson.internal.PlatformUtil.isUnalignedAccessAllowed; |
28 | 27 |
|
29 | 28 | /**
|
30 | 29 | * An implementation of {@code BsonInput} that is backed by a {@code ByteBuf}.
|
|
34 | 33 | public class ByteBufferBsonInput implements BsonInput {
|
35 | 34 |
|
36 | 35 | private static final String[] ONE_BYTE_ASCII_STRINGS = new String[Byte.MAX_VALUE + 1];
|
37 |
| - private static final boolean UNALIGNED_ACCESS_SUPPORTED = isUnalignedAccessAllowed(); |
38 | 36 | /* A dynamically sized scratch buffer, that is reused across BSON String reads:
|
39 | 37 | * 1. Reduces garbage collection by avoiding new byte array creation.
|
40 | 38 | * 2. Improves cache utilization through temporal locality.
|
@@ -184,34 +182,11 @@ public void skipCString() {
|
184 | 182 | buffer.position(pos + length);
|
185 | 183 | }
|
186 | 184 |
|
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 |
| - */ |
191 | 185 | public int computeCStringLength(final int prevPos) {
|
192 | 186 | ensureOpen();
|
193 | 187 | int pos = buffer.position();
|
194 | 188 | int limit = buffer.limit();
|
195 | 189 |
|
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. |
215 | 190 | while (pos < limit) {
|
216 | 191 | if (buffer.get(pos++) == 0) {
|
217 | 192 | return (pos - prevPos);
|
|
0 commit comments