okio icon indicating copy to clipboard operation
okio copied to clipboard

Zero-copy ByteString.slice(offset, length)

Open JakeWharton opened this issue 6 years ago • 2 comments

I have a format represented in-memory as a ByteString and I want to expose parts of that elsewhere in the codebase without causing needless copies.

JakeWharton avatar Oct 12 '19 02:10 JakeWharton

I believe SegmentedByteString behaves like what you describe by sharing segments when calling substring() and just recalculating start and end points. If a similar enhancement was added to ByteString for substring() , would that fit your use case?

bnorm avatar Oct 16 '19 16:10 bnorm

It would, but that behavior may surprise people (for the same reason it used to in String.substring). That's why I proposed a separate method which defines it's behavior as a view into the original bytes.

JakeWharton avatar Oct 16 '19 16:10 JakeWharton