pjfanning commented on code in PR #2924:
URL: https://github.com/apache/pekko/pull/2924#discussion_r3148533146


##########
actor/src/main/scala/org/apache/pekko/util/ByteString.scala:
##########
@@ -1236,61 +1236,69 @@ object ByteString {
     private[pekko] override def readShortBEUnchecked(offset: Int): Short = {
       if (offset + java.lang.Short.BYTES <= firstLength) 
first.readShortBEUnchecked(offset)
       else if (offset >= firstLength) second.readShortBEUnchecked(offset - 
firstLength)
-      else ((byteAt(offset, firstLength) & 0xFF) << 8 | (byteAt(offset + 1, 
firstLength) & 0xFF)).toShort
+      else SWARUtil.getShortBE(byteAt(offset, firstLength), byteAt(offset + 1, 
firstLength))
     }
 
     private[pekko] override def readShortLEUnchecked(offset: Int): Short = {
       if (offset + java.lang.Short.BYTES <= firstLength) 
first.readShortLEUnchecked(offset)
       else if (offset >= firstLength) second.readShortLEUnchecked(offset - 
firstLength)
-      else ((byteAt(offset, firstLength) & 0xFF) | (byteAt(offset + 1, 
firstLength) & 0xFF) << 8).toShort
+      else SWARUtil.getShortLE(byteAt(offset, firstLength), byteAt(offset + 1, 
firstLength))
     }
 
     private[pekko] override def readIntBEUnchecked(offset: Int): Int = {
       if (offset + java.lang.Integer.BYTES <= firstLength) 
first.readIntBEUnchecked(offset)
       else if (offset >= firstLength) second.readIntBEUnchecked(offset - 
firstLength)
-      else
-        (byteAt(offset, firstLength) & 0xFF) << 24 |
-        (byteAt(offset + 1, firstLength) & 0xFF) << 16 |
-        (byteAt(offset + 2, firstLength) & 0xFF) << 8 |
-        (byteAt(offset + 3, firstLength) & 0xFF)
+      else {
+        SWARUtil.getIntBE(
+          byteAt(offset, firstLength),
+          byteAt(offset + 1, firstLength),
+          byteAt(offset + 2, firstLength),
+          byteAt(offset + 3, firstLength))
+      }
     }
 
     private[pekko] override def readIntLEUnchecked(offset: Int): Int = {
       if (offset + java.lang.Integer.BYTES <= firstLength) 
first.readIntLEUnchecked(offset)
       else if (offset >= firstLength) second.readIntLEUnchecked(offset - 
firstLength)
-      else
-        (byteAt(offset, firstLength) & 0xFF) |
-        (byteAt(offset + 1, firstLength) & 0xFF) << 8 |
-        (byteAt(offset + 2, firstLength) & 0xFF) << 16 |
-        (byteAt(offset + 3, firstLength) & 0xFF) << 24
+      else {
+        SWARUtil.getIntLE(

Review Comment:
   We could at least check if the first underlying byte string has enough bytes 
so that we can delegate the call to it.



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