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

[feature request] memchr_inv? #166

Open
cyphar opened this issue Oct 11, 2024 · 1 comment
Open

[feature request] memchr_inv? #166

cyphar opened this issue Oct 11, 2024 · 1 comment

Comments

@cyphar
Copy link

cyphar commented Oct 11, 2024

Sometimes it's necessary to search for the first occurrence that is not a particular byte (the most obvious example is checking if a buffer is all NUL-bytes and returning the first non-NUL byte). For instance, the Linux kernel has a memchr_inv function for this purpose.

The usecase I have at the moment is that I'm writing a C API for libpathrs that I would like to design to mirror a Linux kernel API, and memchr_inv is needed to check whether a passed buffer is zeroed after a point. I have hand-rolled memchr_inv but I suspect it is far less efficient than something that this crate could provide.

(I guess memchr already handles this, but it's probably worth mentioning that the buffer is probably not going to be 4-byte or 8-byte aligned because offset from where we have to check the buffer could be any value and so the slice could start at any offset.)

I guess this can be seen as a duplicate of #157, but with a far more restricted scope (just != as opposed to all comparison operations). But I guess the other option would be to just adapt https://github.com/BurntSushi/bstr/blob/e223ec63cab2de544625b8946e372e6d50ab53d2/src/ascii.rs as suggested in that thread...

@BurntSushi
Copy link
Owner

Yeah, I think what I wrote in #157 still applies. I do want to add things like this (and stuff in #157). And one way of avoiding the compile time hit is to make them opt-in features, particularly since they are somewhat niche needs. I think the bigger problem is review and maintenance bandwidth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants