Improved MultiByteArrayIterator.toByteString

MultiByteArrayIterator.toByteString now returns the optimal ByteString
representation for the data.
This commit is contained in:
Oliver Schulz 2012-05-26 12:28:33 +02:00
parent 0aff0ff101
commit 151b74262e

View file

@ -312,9 +312,12 @@ object ByteIterator {
}
final override def toByteString: ByteString = {
val result = iterators.foldLeft(ByteString.empty) { _ ++ _.toByteString }
clear()
result
if (iterators.tail isEmpty) iterators.head.toByteString
else {
val result = iterators.foldLeft(ByteString.empty) { _ ++ _.toByteString }
clear()
result
}
}
@tailrec protected final def getToArray[A](xs: Array[A], offset: Int, n: Int, elemSize: Int)(getSingle: A)(getMult: (Array[A], Int, Int) Unit): this.type = if (n <= 0) this else {