He-Pin commented on code in PR #2847:
URL: https://github.com/apache/pekko/pull/2847#discussion_r3041116588


##########
stream/src/main/scala/org/apache/pekko/stream/impl/io/ByteStringParser.scala:
##########
@@ -219,13 +219,43 @@ import pekko.util.ByteString
         off += 1
         x & 0xFF
       } else throw NeedMoreData
-    def readShortLE(): Int = readByte() | (readByte() << 8)
-    def readIntLE(): Int = readShortLE() | (readShortLE() << 16)
-    def readLongLE(): Long = (readIntLE() & 0xFFFFFFFFL) | ((readIntLE() & 
0xFFFFFFFFL) << 32)
+    def readShortLE(): Int = {
+      if (off + 2 > input.length) throw NeedMoreData
+      val result = input.readShortLEUnchecked(off) & 0xFFFF
+      off += 2
+      result
+    }
+    def readIntLE(): Int = {
+      if (off + 4 > input.length) throw NeedMoreData
+      val result = input.readIntLEUnchecked(off)
+      off += 4
+      result
+    }
+    def readLongLE(): Long = {
+      if (off + 8 > input.length) throw NeedMoreData
+      val result = input.readLongLEUnchecked(off)
+      off += 8
+      result
+    }
 
-    def readShortBE(): Int = (readByte() << 8) | readByte()
-    def readIntBE(): Int = (readShortBE() << 16) | readShortBE()
-    def readLongBE(): Long = ((readIntBE() & 0xFFFFFFFFL) << 32) | 
(readIntBE() & 0xFFFFFFFFL)
+    def readShortBE(): Int = {
+      if (off + 2 > input.length) throw NeedMoreData
+      val result = input.readShortBEUnchecked(off) & 0xFFFF
+      off += 2
+      result
+    }
+    def readIntBE(): Int = {
+      if (off + 4 > input.length) throw NeedMoreData
+      val result = input.readIntBEUnchecked(off)
+      off += 4
+      result
+    }
+    def readLongBE(): Long = {
+      if (off + 8 > input.length) throw NeedMoreData
+      val result = input.readLongBEUnchecked(off)
+      off += 8
+      result
+    }

Review Comment:
   It would be nice to have some benchmark attached.



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