Align ByteArrays.kt file with O/S to reduce merge conflicts (#1472)

This commit is contained in:
Anthony Keenan 2018-10-10 12:52:09 +02:00 committed by GitHub
parent 4b9dd514c2
commit 09c1e6c079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,7 +33,7 @@ sealed class ByteSequence(private val _bytes: ByteArray, val offset: Int, val si
fun open() = ByteArrayInputStream(_bytes, offset, size)
/**
* Create a sub-sequence of this sequence. A copy of the underlying array may be made, if a subclass overrides
* Create a sub-sequence of this sequence. A copy of the underlying array may be made, if a subclass overrides
* [bytes] to do so, as [OpaqueBytes] does.
*
* @param offset The offset within this sequence to start the new sequence. Note: not the offset within the backing array.
@ -41,10 +41,7 @@ sealed class ByteSequence(private val _bytes: ByteArray, val offset: Int, val si
*/
@Suppress("MemberVisibilityCanBePrivate")
fun subSequence(offset: Int, size: Int): ByteSequence {
require(offset >= 0)
require(offset + size <= this.size)
// Intentionally use bytes rather than _bytes, in case a subclass wants to prevent access to the original
// underlying array which could be revealed here (e.g. OpaqueBytes).
// Intentionally use bytes rather than _bytes, to mirror the copy-or-not behaviour of that property.
return if (offset == 0 && size == this.size) this else of(bytes, this.offset + offset, size)
}