ByteString.apply optimized for Byte

This commit is contained in:
Derek Williams 2011-05-22 13:53:58 -06:00
parent 9ef8ea5ff5
commit 05e93e3f18

View file

@ -11,6 +11,12 @@ object ByteString {
def apply(bytes: Array[Byte]): ByteString = new ByteString(bytes.clone)
def apply(bytes: Byte*): ByteString = {
val ar = new Array[Byte](bytes.size)
bytes.copyToArray(ar)
new ByteString(ar)
}
def apply[T](bytes: T*)(implicit num: Integral[T]): ByteString =
new ByteString(bytes.map(x num.toInt(x).toByte)(collection.breakOut))