add zero-copy constructor to create ByteString from external array
This commit is contained in:
parent
c60d20af32
commit
4684e19828
1 changed files with 20 additions and 0 deletions
|
|
@ -60,6 +60,16 @@ object ByteString {
|
|||
*/
|
||||
def fromArray(array: Array[Byte]): ByteString = apply(array)
|
||||
|
||||
/**
|
||||
* Creates a ByteString without allocation.
|
||||
*
|
||||
* Use with caution:
|
||||
* Since the ByteString is created without copying the byte array,
|
||||
* this makes it unsafe if an array is passed in and mutated afterwards.
|
||||
* DO NOT USE if you are not sure whether the passed-in array will be changed outside this method.
|
||||
*/
|
||||
def fromArrayUnsafe(array: Array[Byte]): ByteString = ByteString1C(array)
|
||||
|
||||
/**
|
||||
* Creates a new ByteString by copying length bytes starting at offset from
|
||||
* an Array.
|
||||
|
|
@ -67,6 +77,16 @@ object ByteString {
|
|||
def fromArray(array: Array[Byte], offset: Int, length: Int): ByteString =
|
||||
CompactByteString.fromArray(array, offset, length)
|
||||
|
||||
/**
|
||||
* Creates a ByteString without allocation, using length bytes starting at offset from an Array.
|
||||
*
|
||||
* Use with caution:
|
||||
* Since the ByteString is created without copying the byte array,
|
||||
* this makes it unsafe if an array is passed in and mutated afterwards.
|
||||
* DO NOT USE if you are not sure whether the passed-in array will be changed outside this method.
|
||||
*/
|
||||
def fromArrayUnsafe(array: Array[Byte], offset: Int, length: Int): ByteString = ByteString1(array, offset, length)
|
||||
|
||||
/**
|
||||
* JAVA API
|
||||
* Creates a new ByteString by copying an int array by converting from integral numbers to bytes.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue