JD557 commented on code in PR #1247: URL: https://github.com/apache/pekko/pull/1247#discussion_r1551385948
########## actor/src/main/scala-2.12/org/apache/pekko/util/ByteString.scala: ########## @@ -790,6 +843,30 @@ sealed abstract class ByteString extends IndexedSeq[Byte] with IndexedSeqOptimiz // optimized in subclasses override def indexOf[B >: Byte](elem: B): Int = indexOf(elem, 0) + // optimized version of indexOf for bytes, optimized in subclasses + /** + * Finds index of first occurrence of some byte in this ByteString after or at some start index. + * + * Similar to indexOf, but it avoids boxing if the value is already a byte. + * + * @param elem the element value to search for. + * @param from the start index + * @return the index `>= from` of the first element of this ByteString that is equal (as determined by `==`) + * to `elem`, or `-1`, if none exists. + */ + def indexOf(elem: Byte, from: Int): Int = indexOf(elem, from) Review Comment: Added the `@since` annotation in 44cf4bccf71cfaed828d81625c603ed1e66e3fab Regarding adding more methods, I think that is a bit out of scope for this PR. I was thinking a bit about that, and I think it would be nice if, when introducing the new methods, they were in sync with the stdlib. For example, it would be pretty bad to introduce a `indexOf(elem:Byte,fromIndex:Int, toIndex:Int)` and then the stdlib introduce a `indexOf(elem:Byte, fromIndex:Int, lenght:Int)`. So, I think one possible way to avoid that would be: 1. Port this PR to https://github.com/mdedetrich/bytestring 2. Try to move the `ByteString` to the stdlib - I think that was one of @mdedetrich main reasons for extracting the code (as discussed in https://contributors.scala-lang.org/t/adding-akkas-bytestring-as-a-scala-module-and-or-stdlib/5967), and I think this should now be possible under [SIP-51](https://github.com/scala/improvement-proposals/pull/54). 3. Propose the new methods to the stdlib, implementing the specialized version where it makes sense. WDYT? -- 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]
