-
Notifications
You must be signed in to change notification settings - Fork 51
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
Safer Repr? #324
Comments
That indeed works, |
Seems like a great idea. I guess we can remove a ton of transmutations and the generated byte code should basically stay the same. And if the compiler better understands what we are doing, maybe it can even do more optimizations. But I guess it would be quite a lot of work to implement that. |
Working on this in https://github.com/goffrie/compact_str/tree/safer-repr. |
Hey Geoffry! I love the idea of reducing the amount of unsafe code, thanks for filing an issue and starting to work on it! A couple of thoughts:
Related to this, I've been toying with a new layout for
We could represent our three states with:
Now a This definitely does not materially reduce the amount of
|
I'd be curious to see how big the execution time difference is for accesses with that change. It's also worth noting that, right now (in |
Unlikely. I am curious to see how much performance this will lose.
Yup. It is quite a bit of extra complexity though just to support relatively unlikely use cases. Losing one byte of inline space to get rid of the representation is probably fine, but it does kind of get rid of the biggest unique point about this crate over other similar ones. |
I had an idea to avoid transmuting
Repr
s around by directly making use of the enum niche optimization. Basically, store([u8; 23], LastUtf8Char)
inInline
, restrictLastUtf8Char
to only actual valid last-bytes for theInline
representation, then have Repr be an enum overInline
/Heap
/&'static str
/ etc as desired, and the compiler will choose the discriminants for those variants.See this Godbolt link.
The text was updated successfully, but these errors were encountered: