Skip to content

Conversation

seanmonstar
Copy link
Member

This separates the SharedVtable into 3:

  • PromotableEvenVtable: The original SharedVtable, which will
    promote the Vec to Shared on the first clone, and is selected when
    the Vec's pointer has the LSB unset.
  • PromotableOddVtable: Similar to the PromotableEvenVtable, but
    selected when the Vec's pointer has the LSB set. This vtable differs
    in the masking used when reconstructing the Vec.
  • SharedVtable: This no longer checks if its current kind is VEC or
    ARC, and is only created by the "promotable" vtables.

This also adds a test using an "odd" global allocator that purposefully
bumps all pointers with alignment of 1.

Closes #343

@@ -731,20 +731,23 @@ impl From<Vec<u8>> for Bytes {
let slice = vec.into_boxed_slice();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_empty special case above can be removed now that the low bit is being tracked properly.

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it

This separates the `SharedVtable` into 3:

- `PromotableEvenVtable`: The original `SharedVtable`, which will
  promote the `Vec` to `Shared` on the first clone, and is selected when
  the `Vec`'s pointer has the LSB unset.
- `PromotableOddVtable`: Similar to the `PromotableEvenVtable`, but
  selected when the `Vec`'s pointer has the LSB set. This vtable differs
  in the masking used when reconstructing the `Vec`.
- `SharedVtable`: This no longer checks if its current kind is `VEC` or
  `ARC`, and is only created by the "promotable" vtables.

This also adds a test using an "odd" global allocator that purposefully
bumps all pointers with alignment of 1.

Closes #343
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.

Bytes assumes that Vec<u8>'s allocation is more than 1 byte aligned
3 participants