pjfanning opened a new pull request, #2847: URL: https://github.com/apache/pekko/pull/2847
## Summary This PR implements the following changes: ### SWARUtil - Added `getShort(array, index)` (big-endian) and `getShort(array, index, bigEndian)` methods using VarHandle byte array views for performance, with fallback implementations `getShortBEWithoutMethodHandle` and `getShortLEWithoutMethodHandle` - Added `shortBeArrayView` and `shortLeArrayView` VarHandle fields - Expanded class-level Scaladoc to document where the JDK itself uses `MethodHandles.byteArrayViewVarHandle` (in `jdk.internal.util.ByteArray` and `jdk.internal.util.ByteArrayLittleEndian`, backing `java.io.DataInputStream` and `java.util.UUID`) and explains the performance benefits: single native load instruction with JIT intrinsification, consolidated bounds check, no alignment requirement, and SWAR arithmetic ### ByteString - Added `readShortBE(offset)`, `readShortLE(offset)`, `readIntBE(offset)`, `readIntLE(offset)`, `readLongBE(offset)`, `readLongLE(offset)` public methods to the `ByteString` abstract class - All public methods throw `IndexOutOfBoundsException` if `offset` is negative or there are insufficient bytes, via a shared `checkReadBounds` helper - All public methods include `@throws[IndexOutOfBoundsException]` Javadoc and are marked `@since 2.0.0` - Added corresponding `private[pekko]` unchecked variants (`readShortBEUnchecked`, `readShortLEUnchecked`, `readIntBEUnchecked`, `readIntLEUnchecked`, `readLongBEUnchecked`, `readLongLEUnchecked`) that skip the bounds check; the public methods delegate to these after checking bounds - `ByteString1C` and `ByteString1` override the unchecked variants with direct SWARUtil calls for optimal performance; `ByteStrings` inherits the byte-by-byte default ### ByteStringParser - Updated `ByteReader.readShortBE/LE`, `readIntBE/LE`, `readLongBE/LE` to delegate to the new `*Unchecked` `ByteString` methods, avoiding a redundant bounds check (the reader already guards with `NeedMoreData`) ### Tests - `SWARUtilSpec`: added `getShort` tests covering both byte orders, VarHandle and fallback paths - `ByteStringSpec`: added correctness tests for all three `ByteString` implementations (`ByteString1C`, `ByteString1`, `ByteStrings`) and bounds-checking tests that verify `IndexOutOfBoundsException` is thrown for negative offsets and insufficient data -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
