-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix: bitwise representation for RGB highlight #13188
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\cc @pascalkuthe In response to #12308 (comment)
Personally, I'd rather see Highlight
defined as
enum Highlight {
Index(u32),
Color(u8, u8, u8),
}
That way it'll still fit into 8 bytes. It's a big regression on 32 bit architectures where this type will now be 8 bytes rather than 4, but packing 3 bytes of color into a 4 byte integer (which is what the code is doing right now) is insufficient since it's possible to have more than 255 items in the highlights array.
We'd need to double check but I think compiled code doing the enum matching should be about as equally efficient as using a u64
then manually doing the bit shifts?
This was actually tried before (turning See this code review comment: #12308 (comment) \cc @the-mikedavis |
Also, on 32 bit architectures which have 4 bytes for a number: We store the RGB color in the last 3 bytes (and only when the highlight is more than Meaning the user can have up to |
I think |
If tree-house uses And |
See https://github.com/helix-editor/tree-house/blob/1fa65eca36fdbb2837e0655bfda53ed627fc25c0/highlighter/src/highlighter.rs#L117-L140 - it's a non-max internally represented as a non-zero, so only the zero pattern is reserved. In order to use the trick of packing an RGB color into the highlight we'd need to subtract and add 1 before storing/accessing the underlying An enum like that would take 8 bytes rather than 4 but we'd still have the null-pointer optimization: |
Instead of using
to_ne_bytes
, we useto_be_bytes
.ne
means Native Endian, so it may different on different platforms -- causing the test to fail and the highlight color to be incorrect on some platforms.We want to use Big Endian representation because we store the r, g, b in the last 3 bytes. this nicely maps onto big endian representation
thanks @Rudxain https://github.com/helix-editor/helix/pull/12308/files#r2010969852 for finding this.
@RoloEdits https://github.com/helix-editor/helix/pull/12308/files#r2010998709 has a nice image to showcase this "endianness"