He-Pin commented on code in PR #3430:
URL: https://github.com/apache/pekko/pull/3430#discussion_r3789062253
##########
actor/src/main/scala/org/apache/pekko/util/ByteString.scala:
##########
@@ -1393,15 +1393,29 @@ object ByteString {
if (offset + java.lang.Long.BYTES <= firstLen)
first.readLongBEUnchecked(offset)
else if (offset >= firstLen) second.readLongBEUnchecked(offset -
firstLen)
else {
- SWARUtil.getLongBE(
- byteAt(offset, firstLen),
- byteAt(offset + 1, firstLen),
- byteAt(offset + 2, firstLen),
- byteAt(offset + 3, firstLen),
- byteAt(offset + 4, firstLen),
- byteAt(offset + 5, firstLen),
- byteAt(offset + 6, firstLen),
- byteAt(offset + 7, firstLen))
+ // Cross-boundary: build two sub-longs from byteAtUnchecked and
combine.
+ // byteAtUnchecked is a single virtual call per byte (no extra branch
per byte),
+ // and the Long assembly is pure arithmetic with no per-byte branching.
+ val split = firstLen - offset // bytes in first fragment (1-7)
+ val firstPart = {
+ var i = offset
+ var v = 0L
+ while (i < firstLen) {
+ v = (v << 8) | (first.byteAtUnchecked(i).toLong & 0xFF)
+ i += 1
+ }
+ v << ((8 - split) << 3)
+ }
Review Comment:
use a private method with @inline annotation?
--
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]