Closed anuragsoni closed 3 years ago
Thanks for the patch. I've imported it into our internal code review system.
FYI, unsafe
here is really supposed to mean "no bounds checking". It usually also implies that the code using it is carefully tuned for performance and avoiding allocation, so that's why it would return -1 instead of an option. Is that your use case, or do you have some other reason you want a version of this function which returns a negative number?
@bcc32 It usually also implies that the code using it is carefully tuned for performance and avoiding allocation, so that's why it would return -1 instead of an option. Is that your use case
This was indeed the usecase I want. I struggled with name as I believe spos
does perform bounds checking. Maybe using https://github.com/janestreet/core_kernel/blob/1b079252ad82677f3f960b951e1aa836d6fb1c91/iobuf/src/iobuf.ml#L433 directly is more appropriate for a function like this? (with appropriate warning in the documentation).
Got it. Yes, unsafe_buf_pos
sounds like what you want. (I'm making these changes internally, so you don't have to do anything to this PR. It would be updated when we merge it in our next GitHub update.)
I'm making these changes internally, so you don't have to do anything to this PR. It would be updated when we merge it in our next GitHub update.
Thanks!
we moved the function to be named Iobuf.Unsafe.Peek.index_or_neg
to conform to existing convention in this library. _or_neg
is meant as a helpful reminder to the caller, of a property which unsafe
itself does not suggest.
we moved the function to be named
Iobuf.Unsafe.Peek.index_or_neg
to conform to existing convention in this library._or_neg
is meant as a helpful reminder to the caller, of a property whichunsafe
itself does not suggest.
This sounds very reasonable. I like this name more than unsafe_index
!
This can probably be closed now as https://github.com/janestreet/core_kernel/commit/5d5af9a4a7c412c1d92d0e0f1d169511e7888e5e adds this new function!
You're right. I thought we had some sort of automation for this but maybe it didn't work. Thank you for contributing to this library!
Similar to
index
but returns -1 instead ofNone
to indicateNot_found
.Signed-off-by: Anurag Soni anurag@sonianurag.com