Optimize ByteString.grouped(size) (#25153)

* Add ByteString.grouped() benchmark & tests.

* Implement ByteString.grouped().

* PR comments.
This commit is contained in:
Doug Roper 2018-05-30 10:31:35 -04:00 committed by Konrad `ktoso` Malawski
parent a14347e18d
commit b6d6d543a8
3 changed files with 58 additions and 0 deletions

View file

@ -52,6 +52,15 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
} yield (xs, from, until)
}
case class ByteStringGrouped(bs: ByteString, size: Int)
implicit val arbitraryByteStringGrouped = Arbitrary {
for {
xs arbitraryByteString.arbitrary
size Gen.choose(1, 1 max xs.length)
} yield ByteStringGrouped(xs, size)
}
type ArraySlice[A] = (Array[A], Int, Int)
def arbSlice[A](arbArray: Arbitrary[Array[A]]): Arbitrary[ArraySlice[A]] = Arbitrary {
@ -730,6 +739,14 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
}
}
"calling grouped" in {
check { grouped: ByteStringGrouped
likeVector(grouped.bs) {
_.grouped(grouped.size).toIndexedSeq
}
}
}
"calling copyToArray" in {
check { slice: ByteStringSlice
slice match {