Skip to content

Option<SmallVecN<T>> breaks the non-zero optimization #5

Closed
@SimonSapin

Description

@SimonSapin

This currently fails:

assert!(Some(SmallVec4::<&u32>::new()).is_some());

This is because SmallVec<&u32> contains a [&u32; 4] field directly, and the compiler choses to use one of those &u32 (which are non-zero) to set to zero to represent None in Option<SmallVec<&u32>>. However, new initializes the array with std::mem::zeroed(), which conflicts with this optimization.

https://github.com/bluss/arrayvec works around this by using #[repr(u8)] on an enum. (The one used to make drop sound, see #4.)

CC @pcwalton

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions