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

hepin 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 c708891504 chore: Use while loop (#2155)
c708891504 is described below

commit c7088915044c523970ea85571bd5f0a493b7c7d8
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Sat Sep 6 17:10:32 2025 +0800

    chore: Use while loop (#2155)
---
 .../org/apache/pekko/util/ByteString.scala         |  4 +++-
 .../org/apache/pekko/util/ByteString.scala         |  5 +++--
 .../scala-3/org/apache/pekko/util/ByteString.scala |  4 +++-
 .../org/apache/pekko/actor/dungeon/Children.scala  |  9 ++++++++-
 .../scala/org/apache/pekko/util/LineNumbers.scala  | 22 ++++++++++++++++++----
 .../apache/pekko/cluster/ddata/Replicator.scala    |  5 ++++-
 6 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/actor/src/main/scala-2.12/org/apache/pekko/util/ByteString.scala 
b/actor/src/main/scala-2.12/org/apache/pekko/util/ByteString.scala
index 9855a19fe3..05b60a2cad 100644
--- a/actor/src/main/scala-2.12/org/apache/pekko/util/ByteString.scala
+++ b/actor/src/main/scala-2.12/org/apache/pekko/util/ByteString.scala
@@ -523,10 +523,12 @@ object ByteString {
 
       builder.sizeHint(nByteStrings)
 
-      for (_ <- 0 until nByteStrings) {
+      var i = 0
+      while (i < nByteStrings) {
         val bs = ByteString1.readFromInputStream(is)
         builder += bs
         length += bs.length
+        i += 1
       }
 
       new ByteStrings(builder.result(), length)
diff --git a/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala 
b/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala
index 10886bf26e..5db8d7e45c 100644
--- a/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala
+++ b/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala
@@ -531,12 +531,13 @@ object ByteString {
 
       builder.sizeHint(nByteStrings)
 
-      for (_ <- 0 until nByteStrings) {
+      var i = 0
+      while (i < nByteStrings) {
         val bs = ByteString1.readFromInputStream(is)
         builder += bs
         length += bs.length
+        i += 1
       }
-
       new ByteStrings(builder.result(), length)
     }
   }
diff --git a/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala 
b/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala
index 8aa06c5eec..3234963538 100644
--- a/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala
+++ b/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala
@@ -532,10 +532,12 @@ object ByteString {
 
       builder.sizeHint(nByteStrings)
 
-      for (_ <- 0 until nByteStrings) {
+      var i = 0
+      while (i < nByteStrings) {
         val bs = ByteString1.readFromInputStream(is)
         builder += bs
         length += bs.length
+        i += 1
       }
 
       new ByteStrings(builder.result(), length)
diff --git a/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala 
b/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala
index 02b6d0ed4b..89f5d9dfc6 100644
--- a/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala
+++ b/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala
@@ -330,7 +330,14 @@ private[pekko] trait Children { this: ActorCell =>
             throw e
         }
       // mailbox==null during RoutedActorCell constructor, where suspends are 
queued otherwise
-      if (mailbox ne null) for (_ <- 1 to mailbox.suspendCount) actor.suspend()
+      if (mailbox ne null) {
+        val suspendCount = mailbox.suspendCount
+        var i = 1
+        while (i <= suspendCount) {
+          actor.suspend()
+          i += 1
+        }
+      }
       initChild(actor)
       actor.start()
       actor
diff --git a/actor/src/main/scala/org/apache/pekko/util/LineNumbers.scala 
b/actor/src/main/scala/org/apache/pekko/util/LineNumbers.scala
index 648d790ed9..5d22f9d79f 100644
--- a/actor/src/main/scala/org/apache/pekko/util/LineNumbers.scala
+++ b/actor/src/main/scala/org/apache/pekko/util/LineNumbers.scala
@@ -253,16 +253,22 @@ object LineNumbers {
 
   private def skipInterfaceInfo(d: DataInputStream)(implicit c: Constants): 
Unit = {
     val count = d.readUnsignedShort()
-    for (_ <- 1 to count) {
+    var i = 1
+    while (i <= count) {
       val intf = d.readUnsignedShort()
       if (debug) println(s"LNB:   implements ${c(intf)}")
+      i += 1
     }
   }
 
   private def skipFields(d: DataInputStream)(implicit c: Constants): Unit = {
     val count = d.readUnsignedShort()
     if (debug) println(s"LNB: reading $count fields:")
-    for (_ <- 1 to count) skipMethodOrField(d)
+    var i = 1
+    while (i <= count) {
+      skipMethodOrField(d)
+      i += 1
+    }
   }
 
   private def skipMethodOrField(d: DataInputStream)(implicit c: Constants): 
Unit = {
@@ -270,7 +276,11 @@ object LineNumbers {
     val name = d.readUnsignedShort() // name
     skip(d, 2) // signature
     val attributes = d.readUnsignedShort()
-    for (_ <- 1 to attributes) skipAttribute(d)
+    var i = 1
+    while (i <= attributes) {
+      skipAttribute(d)
+      i += 1
+    }
     if (debug) println(s"LNB:   ${c(name)} ($attributes attributes)")
   }
 
@@ -295,7 +305,11 @@ object LineNumbers {
       }
     } else {
       if (debug) println(s"LNB:   (skipped)")
-      for (_ <- 1 to count) skipMethodOrField(d)
+      var i = 1
+      while (i <= count) {
+        skipMethodOrField(d)
+        i += 1
+      }
       None
     }
   }
diff --git 
a/distributed-data/src/main/scala/org/apache/pekko/cluster/ddata/Replicator.scala
 
b/distributed-data/src/main/scala/org/apache/pekko/cluster/ddata/Replicator.scala
index 39749f1687..e3ff9ccc2f 100644
--- 
a/distributed-data/src/main/scala/org/apache/pekko/cluster/ddata/Replicator.scala
+++ 
b/distributed-data/src/main/scala/org/apache/pekko/cluster/ddata/Replicator.scala
@@ -1971,7 +1971,9 @@ final class Replicator(settings: ReplicatorSettings) 
extends Actor with ActorLog
       to ! status
     } else {
       val totChunks = dataEntries.size / maxDeltaElements
-      for (_ <- 1 to math.min(totChunks, 10)) {
+      var i = 1
+      val maxLoop = math.min(totChunks, 10)
+      while (i <= maxLoop) {
         if (totChunks == statusTotChunks)
           statusCount += 1
         else {
@@ -1983,6 +1985,7 @@ final class Replicator(settings: ReplicatorSettings) 
extends Actor with ActorLog
             case (key, (_, _)) if math.abs(key.hashCode % totChunks) == chunk 
=> (key, getDigest(key))
           }, chunk, totChunks, toSystemUid, selfFromSystemUid)
         to ! status
+        i += 1
       }
     }
   }


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

Reply via email to