Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #47.
As far as I can tell, there was no real need to use
MaybeUninit<InlineString>
instead of justInlineString
directly, due to it being a POD type. All that was required was changing the types of pointer casts we do to directly use&self.data as *const _
rather thanself.data.as_ptr()
in various places.Due to no longer using the
MaybeUninit
union type, we are able to getOption
size optimization out of theInlineString
. To do this, I changedMarker(u8)
toMarker(NonZeroU8)
and changed it to use the low 2 bits for storing both the discriminant (as it already did), and also a non-zero bit to guarantee the requirement ofNonZeroU8
. I've also changed the allocator alignment requirement to 4 instead of 2 to guarantee these bits are free to use; this should not cause issues on 32 or 64 bit systems, which are our targets.To ensure that a
BoxedString
write over the memory of theInlineString
does not violate the requirements ofNonZeroU8
(and/or produce aNone
value), theptr
field inBoxedString
was changed to a newTaggedPtr
type that automatically handles setting the low 2 bits appropriately (and removing them when queried).I feel that additional testing should be done, but it currently passes all existing test cases and a few that I added specifically about size requirements and
Some
vsNone
checks for small and large strings.