New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ByteBuffer: improve and simplify get* implementations #896
Conversation
return nil | ||
} | ||
|
||
return ByteBufferView(buffer: self, range: index0 ..< index0+length) | ||
return ByteBufferView(buffer: self, range: index ..< (index + length)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use the range-generation function here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lukasa ByteBufferView
uses (and has to use as Collection
) absolute ByteBuffer indices so here, we're not interested in range relative to readable bytes but range relative to the whole ByteBuffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, I see that.
This represents a difficulty with the requirement that ByteBufferView
s only index readable bytes: specifically, what is readable can change after the ByteBufferView
is created, without invalidating the ByteBufferView
itself. I don't think this particularly matters much, as this will only happen if you're going outside the standard NIO usage patterns, but it's worth being aware of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lukasa no, ByteBufferView
holds a (private) ByteBuffer
which is a value, so the readable bytes can't change.
Motivation: For historic reasons, the get* implementations checked the same indices repeatedly and the checks were also repetitive. Modifications: unify and de-deplicate get* range checks Result: fixes apple#884
Motivation:
For historic reasons, the get* implementations checked the same indices
repeatedly and the checks were also repetitive.
Modifications:
unify and de-deplicate get* range checks
Result: