He-Pin commented on code in PR #2148:
URL: https://github.com/apache/pekko/pull/2148#discussion_r2326563466
##########
actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:
##########
@@ -243,17 +243,57 @@ object ByteString {
}
}
+ @nowarn
override def indexOf(elem: Byte, from: Int): Int = {
- if (from >= length) -1
- else {
- var found = -1
- var i = math.max(from, 0)
- while (i < length && found == -1) {
- if (bytes(i) == elem) found = i
- i += 1
- }
- found
+ val fromIndex = math.max(0, from)
+ if (fromIndex >= length) return -1
+ val searchLength = length - fromIndex
+ var offset = fromIndex
+ val byteCount = searchLength & 7
+ if (byteCount > 0) {
+ val index = unrolledFirstIndexOf(fromIndex, byteCount, elem)
+ if (index != -1) return index
+ offset += byteCount
+ if (offset == length) return -1
}
+ val longCount = searchLength >>> 3
+ val pattern = SWARUtil.compilePattern(elem)
+ for (_ <- 0 until longCount) {
Review Comment:
use while loop
##########
actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:
##########
@@ -447,17 +487,59 @@ object ByteString {
}
}
+ @nowarn
override def indexOf(elem: Byte, from: Int): Int = {
- if (from >= length) -1
- else {
- var found = -1
- var i = math.max(from, 0)
- while (i < length && found == -1) {
- if (bytes(startIndex + i) == elem) found = i
- i += 1
- }
- found
+ val fromIndex = startIndex + math.max(0, from)
+ if (fromIndex >= length) return -1
+ val searchLength = length - fromIndex
+ var offset = fromIndex
+ val byteCount = searchLength & 7
+ if (byteCount > 0) {
+ val index = unrolledFirstIndexOf(fromIndex, byteCount, elem)
+ if (index != -1) return index
+ offset += byteCount
+ if (offset == length) return -1
}
+ val longCount = searchLength >>> 3
+ val pattern = SWARUtil.compilePattern(elem)
+ for (_ <- 0 until longCount) {
Review Comment:
use while loop
--
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]