-
Notifications
You must be signed in to change notification settings - Fork 141
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
null terminated bytestrings? #483
Comments
You cannot retain constant-time slicing for null-terminated strings. |
My suggestion wasn't to change the internal representation of |
Trade offs and API would be vastly different from bytestring, so I don’t really see it fit into it. We can discuss adding cbits implementation for findIndex instead. |
It wouldn't even need to be a full findIndex' :: [Word8]
-> ByteString
-> Maybe (Int, Word8) I'm not sure whether I have any visions about how to implement this fast. |
Something like this could be implemented very efficiently, even without cbits: newtype Mask = Mask ByteString -- 256 bits = 32 bytes
findIndexInMask :: Mask -> ByteString -> Maybe (Int, Word8) |
This is more of a discussion/question than an issue.
I was looking into calling into the libc function strpbrk, because it is much faster than any equivalent of
findIndex
could be, see:But then I noticed... Haskell bytestrings are not null-terminated and doing so would require an entire memcpy, which kind of defeats the purpose when looking for optimization.
So I wondered:
strpbrk
and a "pure Haskell implementation"Text
be an alternative? The main reason I use ByteString for this task is because it has those very fastelemIndex
functions implemented viamemchr
.I think there might be many more such C functions, that are not re-implemented for ByteString exactly for that reason.
The text was updated successfully, but these errors were encountered: