You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some use cases (like returning a pointer by a symbol in FFI scenario) it is needed to look up a value by a given *const c_char, without assuming anything about the encoding except that a single NUL byte always ends the sequence. In this regard it could be similar to a binary lookup, but without having the length of the input sequence as an immediate value beforehand.
Is it reasonable to provide a specialized routine for incremental comparison to save cycles by not performing the length count in a separate pass?
The text was updated successfully, but these errors were encountered:
Thinking about this more, I'm not sure if hiding the unsafety of looking for a \0 behind a raw pointer is worth saving an extra scan of the string since the initial length finding will bring it into cache anyway.
@abonander The unsafety can be dealt with in strncmp-esque manner, by having a wrapper type with both a c_char pointer and a maximum length, not actual length. (A slice might work here too, I guess? It’s the semantics of stopping at null character that’s important, anyway.)
And I think the caching might not always work as intended in low-end embedded environments such as Cortex-M0. Individual cycles can be pretty expensive there, especially in real-time tasks.
In some use cases (like returning a pointer by a symbol in FFI scenario) it is needed to look up a value by a given
*const c_char
, without assuming anything about the encoding except that a single NUL byte always ends the sequence. In this regard it could be similar to a binary lookup, but without having the length of the input sequence as an immediate value beforehand.Is it reasonable to provide a specialized routine for incremental comparison to save cycles by not performing the length count in a separate pass?
The text was updated successfully, but these errors were encountered: