From 9865a4e3e1e4dfa2abcaa873f12c5c9251e8539d Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Sun, 27 May 2012 01:58:17 +0200 Subject: [PATCH] Added specialized implementation of foreach to MultiByteArrayIterator --- akka-actor/src/main/scala/akka/util/ByteIterator.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/akka-actor/src/main/scala/akka/util/ByteIterator.scala b/akka-actor/src/main/scala/akka/util/ByteIterator.scala index 52f0d96ced..ad2d93e6d2 100644 --- a/akka-actor/src/main/scala/akka/util/ByteIterator.scala +++ b/akka-actor/src/main/scala/akka/util/ByteIterator.scala @@ -314,6 +314,11 @@ object ByteIterator { normalize() } + override def foreach[@specialized U](f: Byte ⇒ U): Unit = { + iterators foreach { _ foreach f } + clear() + } + final override def toByteString: ByteString = { if (iterators.tail isEmpty) iterators.head.toByteString else { @@ -474,12 +479,12 @@ abstract class ByteIterator extends BufferedIterator[Byte] { override def toSeq: ByteString = toByteString - @inline final override def foreach[@specialized U](f: Byte ⇒ U): Unit = + override def foreach[@specialized U](f: Byte ⇒ U): Unit = while (hasNext) f(next()) final override def foldLeft[@specialized B](z: B)(op: (B, Byte) ⇒ B): B = { var acc = z - while (hasNext) acc = op(acc, next()) + foreach { byte ⇒ acc = op(acc, byte) } acc }