This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git


The following commit(s) were added to refs/heads/main by this push:
     new 8e6501bd75 small optimisation on indexOf (#2863)
8e6501bd75 is described below

commit 8e6501bd75c12e1a6e9da62d67b8d0ccae186337
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Apr 16 17:50:53 2026 +0200

    small optimisation on indexOf (#2863)
---
 .../scala/org/apache/pekko/util/ByteString.scala   | 40 +++++++++++++---------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/actor/src/main/scala/org/apache/pekko/util/ByteString.scala 
b/actor/src/main/scala/org/apache/pekko/util/ByteString.scala
index c36ac54b70..c1d25d8bcb 100644
--- a/actor/src/main/scala/org/apache/pekko/util/ByteString.scala
+++ b/actor/src/main/scala/org/apache/pekko/util/ByteString.scala
@@ -234,14 +234,18 @@ object ByteString {
       else toByteString1.drop(n)
 
     override def indexOf[B >: Byte](elem: B, from: Int): Int = {
-      if (from >= length) -1
-      else {
-        var i = math.max(from, 0)
-        while (i < length) {
-          if (bytes(i) == elem) return i
-          i += 1
-        }
-        -1
+      elem match {
+        case byte: Byte => indexOf(byte, from)
+        case _          =>
+          if (from >= length) -1
+          else {
+            var i = math.max(from, 0)
+            while (i < length) {
+              if (bytes(i) == elem) return i
+              i += 1
+            }
+            -1
+          }
       }
     }
 
@@ -562,14 +566,18 @@ object ByteString {
     }
 
     override def indexOf[B >: Byte](elem: B, from: Int): Int = {
-      if (from >= length) -1
-      else {
-        var i = math.max(from, 0)
-        while (i < length) {
-          if (bytes(startIndex + i) == elem) return i
-          i += 1
-        }
-        -1
+      elem match {
+        case byte: Byte => indexOf(byte, from)
+        case _          =>
+          if (from >= length) -1
+          else {
+            var i = math.max(from, 0)
+            while (i < length) {
+              if (bytes(startIndex + i) == elem) return i
+              i += 1
+            }
+            -1
+          }
       }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to