pjfanning commented on code in PR #2271:
URL: https://github.com/apache/pekko/pull/2271#discussion_r2379565102
##########
actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:
##########
@@ -257,6 +257,20 @@ object ByteString {
}
}
+ override def indexOf(elem: Byte, from: Int, to: Int): Int = {
+ if (from >= length || to <= from) -1
+ else {
+ val upto = math.min(to, length)
+ var found = -1
+ var i = math.max(from, 0)
+ while (i < upto && found == -1) {
+ if (bytes(i) == elem) found = i
+ i += 1
+ }
+ found
Review Comment:
* this is a copy/paste of the existing `indexOf(Byte, Int)`
* I am not against changing this but I should then also change the existing
`indexOf` methods too
Is the idea to change
```
var found = -1
while (i < upto && found == -1) {
if (bytes(startIndex + i) == elem) found = i
i += 1
}
found
}
```
to this?
```
while (i < upto && found == -1) {
if (bytes(startIndex + i) == elem) return i
i += 1
}
-1
}
```
This saves having to do the while check one final time at the end of the
loop. Not a huge win but should make a minor improvement in performance.
Purists will hate the explicit returns.
--
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]