Skip to content
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

Merged
merged 5 commits into from Mar 13, 2019

Conversation

Projects
None yet
2 participants
@weissi
Copy link
Member

weissi commented Mar 11, 2019

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:

Show resolved Hide resolved Sources/NIO/ByteBuffer-core.swift Outdated
return nil
}

return ByteBufferView(buffer: self, range: index0 ..< index0+length)
return ByteBufferView(buffer: self, range: index ..< (index + length))

This comment has been minimized.

@Lukasa

Lukasa Mar 12, 2019

Contributor

Can we not use the range-generation function here?

This comment has been minimized.

@weissi

weissi Mar 12, 2019

Author Member

@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

This comment has been minimized.

@Lukasa

Lukasa Mar 13, 2019

Contributor

Ah, yeah, I see that.

This represents a difficulty with the requirement that ByteBufferViews 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.

This comment has been minimized.

@weissi

weissi Mar 13, 2019

Author Member

@Lukasa no, ByteBufferView holds a (private) ByteBuffer which is a value, so the readable bytes can't change.

ByteBuffer: improve and simplify get* implementations
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 #884

@weissi weissi force-pushed the weissi:jw-884 branch from 45b7819 to 63ee96b Mar 12, 2019

weissi added some commits Mar 12, 2019

@Lukasa

Lukasa approved these changes Mar 13, 2019

weissi added some commits Mar 13, 2019

@weissi weissi merged commit 357b931 into apple:master Mar 13, 2019

1 check passed

pull request validation (5.0) Build finished.
Details

@weissi weissi deleted the weissi:jw-884 branch Mar 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.