-
Notifications
You must be signed in to change notification settings - Fork 634
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
ByteBufferView: implement most Collection/Sequence customisation points #1385
Comments
I'm trying to resolve this task but it makes confused when you said
I thought that we should check |
@trungducc thank you, that's awesome. I think this is just a misunderstanding. I think we need to compare that the |
@weissi Oh yes. That makes sense. I didn't think about it. Thank you for pointing out! |
Added |
|
Hi @weissi, I checked for Edit: I've opened PR #2226 for this issue, at the same time I noticed that swift core has defined all 3 variants of _failEarlyRangeCheck(https://github.com/apple/swift/blob/main/stdlib/public/core/Collection.swift#L711-L734) in the default implementation of |
All subtasks here are completed. |
ByteBufferView
is aCollection
ofUInt8
which "views" into aByteBuffer
. Right now, we basically only implement thesubscript
which vends individual bytes. That's good enough to implementCollection
/Sequence
(and a bunch of more specialised sub-protocols) but it's not very fast at all.Especially methods like
firstIndex(of:)
orfirstIndex(where:)
will be very slow because it'll repeatedly call the subscript for every byte. It would be much faster to just forward theCollection
/Sequence
customisation points directly to the underlying bytes.Generally, this will look something like
so essentially we just forward all operations into the
UnsafeRawBufferPointer
to the bytes thisByteBufferView
contains.The
Collection
customisation points we should implement are_customIndexOfEquatableElement
usingptr.firstIndex(of:)
[done in Add custom index methods to ByteBufferView #1394]_customLastIndexOfEquatableElement
usingptr.lastIndex(of:)
[done in Add custom index methods to ByteBufferView #1394]_failEarlyRangeCheck
by just checking theself._range
[done in NIOCore: Implemented all three variants of _failEarlyRangeCheck methods for ByteBufferView #2226]_customContainsEquatableElement
usingptr.contains()
_copyToContiguousArray
_copyContents
We also don't need to implement all of those in one go, this can be done in multiple PRs.
Some notes:
The text was updated successfully, but these errors were encountered: