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

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

Closed
SimonSapin opened this issue May 24, 2015 · 0 comments
Closed

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

SimonSapin opened this issue May 24, 2015 · 0 comments

Comments

@SimonSapin
Copy link
Member

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

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

No branches or pull requests

1 participant