pjfanning opened a new pull request, #2838:
URL: https://github.com/apache/pekko/pull/2838

   `ByteArrayIterator.getShort/getInt/getLong` called `next()` 2/4/8 times 
individually. `ByteString.lastIndexOf` fell back to element-by-element scan. 
`ByteString.hashCode` was recomputed on every call despite immutability.
   
   ## SWARUtil — extended VarHandle infrastructure
   - Added `byteArrayViewVarHandle` instances for `short` (BE+LE), `int` 
(BE+LE), `long` (LE)
   - Added `getShort(array, index, bigEndian)`, `getInt(...)`, `getLong(array, 
index, bigEndian)` using VarHandle with manual bit-shift fallback
   - Added `getLastIndex(word)` — finds rightmost byte match in SWAR result 
using `numberOfTrailingZeros`
   
   ## ByteIterator (Scala 2.13 + Scala 3) — VarHandle-based multi-byte reads
   Overrides `getShort`/`getInt`/`getLong` in `ByteArrayIterator` to read 
directly from the underlying byte array via `SWARUtil` in a single VarHandle 
call. On Java 17 the JIT lowers these to a single native load, vs. 8 sequential 
bounds-checked element reads before.
   
   ```scala
   // Before: 8 calls to next(), each bounds-checking array(from++)
   override def getLong(implicit byteOrder: ByteOrder): Long = ...
   
   // After: one VarHandle load directly into a long
   override def getLong(implicit byteOrder: ByteOrder): Long = {
     if (len < 8) throw new NoSuchElementException("next on empty iterator")
     val result = SWARUtil.getLong(array, from, byteOrder == 
ByteOrder.BIG_ENDIAN)
     from += 8
     result
   }
   ```


-- 
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]

Reply via email to