Optimize ByteString.grouped(size) (#25153)
* Add ByteString.grouped() benchmark & tests. * Implement ByteString.grouped(). * PR comments.
This commit is contained in:
parent
a14347e18d
commit
b6d6d543a8
3 changed files with 58 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue