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

New implementation #8

Closed
wants to merge 9 commits into from
Closed

Conversation

AnttiParaoanu
Copy link

New implementation works as follows:

  • Store the discriminant bit in the most significant bit of SmartString
  • Arrange the fields of ´BoxedString´ so that the discriminant bit is the most significant bit of capacity or size
    • If on a little endian arch and lazy_null_pointer_optimizations is disabled, use size, otherwise capacity
  • Since transmuting into a String is not guranteed to work, boxed string methods use a new struct called StringReference, which contains a reference to a SmartString, and a String. At the end of it's lifetime the contents of the String are transferred to the SmartString. This replaces try_demote

Null pointer optimizations:

  • If the string is inlined, the discriminant bit is set, so the usize it is a part of (in the boxed version) is not zero
  • If the string is boxed, the capacity is not zero
  • If the string is boxed, and the mode is Compact, the size is also not zero

Things to do:

@bodil
Copy link
Owner

bodil commented Jul 9, 2020

OK, it's going to take me a while to read through all this, but it looks very interesting.

If nothing else, the lazy_null_pointer_optimizations feature flag needs to be shortened, it's a bit of a mouthful, but I'd like to benchmark it a bit to see if it could just be removed.

@bodil bodil self-assigned this Jul 9, 2020
bodil added a commit that referenced this pull request Feb 23, 2022
Stop relying on undefined behaviour.

`smartstring` now implements its own boxed string type rather than deferring directly to `String`, so it no longer makes assumptions it shouldn't be making about the layout of the `String` struct.

This also allows us to organise the boxed struct in a way that will let us rely only on our basic assumption that heap memory is word aligned on both big and little endian architectures. The most immediate consequence of this is that `smartstring` will now compile on 32-bit big endian architectures such as `mips`.

Closes #4 #8 #14
@bodil bodil closed this Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants