diff --git a/akka-actor/src/main/scala/akka/util/ByteIterator.scala b/akka-actor/src/main/scala/akka/util/ByteIterator.scala index ad2d93e6d2..10a6ab64ac 100644 --- a/akka-actor/src/main/scala/akka/util/ByteIterator.scala +++ b/akka-actor/src/main/scala/akka/util/ByteIterator.scala @@ -58,11 +58,11 @@ object ByteIterator { final override def length: Int = { val l = len; clear(); l } final override def ++(that: TraversableOnce[Byte]): ByteIterator = that match { - case that: ByteIterator ⇒ { + case that: ByteIterator ⇒ if (that.isEmpty) this else if (this.isEmpty) that else that match { - case that: ByteArrayIterator ⇒ { + case that: ByteArrayIterator ⇒ if ((this.array eq that.array) && (this.until == that.from)) { this.until = that.until that.clear() @@ -72,10 +72,8 @@ object ByteIterator { this.clear() result } - } case that: MultiByteArrayIterator ⇒ this +: that } - } case _ ⇒ super.++(that) } @@ -230,24 +228,21 @@ object ByteIterator { } final override def ++(that: TraversableOnce[Byte]): ByteIterator = that match { - case that: ByteIterator ⇒ { + case that: ByteIterator ⇒ if (that.isEmpty) this else if (this.isEmpty) that else { that match { - case that: ByteArrayIterator ⇒ { + case that: ByteArrayIterator ⇒ iterators = this.iterators :+ that that.clear() this - } - case that: MultiByteArrayIterator ⇒ { + case that: MultiByteArrayIterator ⇒ iterators = this.iterators ++ that.iterators that.clear() this - } } } - } case _ ⇒ super.++(that) } @@ -410,10 +405,7 @@ abstract class ByteIterator extends BufferedIterator[Byte] { protected def clear(): Unit - def ++(that: TraversableOnce[Byte]): ByteIterator = { - if (that.isEmpty) this - else ByteIterator.ByteArrayIterator(that.toArray) - } + def ++(that: TraversableOnce[Byte]): ByteIterator = if (that.isEmpty) this else ByteIterator.ByteArrayIterator(that.toArray) // *must* be overridden by derived classes. This construction is necessary // to specialize the return type, as the method is already implemented in diff --git a/akka-actor/src/main/scala/akka/util/ByteString.scala b/akka-actor/src/main/scala/akka/util/ByteString.scala index 383371db0d..128373076d 100644 --- a/akka-actor/src/main/scala/akka/util/ByteString.scala +++ b/akka-actor/src/main/scala/akka/util/ByteString.scala @@ -142,11 +142,10 @@ object ByteString { else if (this.isEmpty) that else that match { case b: ByteString1C ⇒ ByteStrings(this, b.toByteString1) - case b: ByteString1 ⇒ { + case b: ByteString1 ⇒ if ((bytes eq b.bytes) && (startIndex + length == b.startIndex)) new ByteString1(bytes, startIndex, length + b.length) else ByteStrings(this, b) - } case bs: ByteStrings ⇒ ByteStrings(this, bs) } } @@ -223,10 +222,7 @@ object ByteString { } } - def isCompact: Boolean = { - if (bytestrings.length == 1) bytestrings.head.isCompact - else false - } + def isCompact: Boolean = if (bytestrings.length == 1) bytestrings.head.isCompact else false def compact: CompactByteString = { if (isCompact) bytestrings.head.compact @@ -555,7 +551,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { */ def putInt(x: Int)(implicit byteOrder: ByteOrder): this.type = { fillArray(4) { - case (target, offset) ⇒ { + case (target, offset) ⇒ if (byteOrder == ByteOrder.BIG_ENDIAN) { target(offset + 0) = (x >>> 24).toByte target(offset + 1) = (x >>> 16).toByte @@ -567,7 +563,6 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { target(offset + 2) = (x >>> 16).toByte target(offset + 3) = (x >>> 24).toByte } else throw new IllegalArgumentException("Unknown byte order " + byteOrder) - } } this } @@ -577,7 +572,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { */ def putLong(x: Long)(implicit byteOrder: ByteOrder): this.type = { fillArray(8) { - case (target, offset) ⇒ { + case (target, offset) ⇒ if (byteOrder == ByteOrder.BIG_ENDIAN) { target(offset + 0) = (x >>> 56).toByte target(offset + 1) = (x >>> 48).toByte @@ -597,7 +592,6 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] { target(offset + 6) = (x >>> 48).toByte target(offset + 7) = (x >>> 56).toByte } else throw new IllegalArgumentException("Unknown byte order " + byteOrder) - } } this }