You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[allow(dead_code)]enumStrOrChar<'a>{Str(&'a str),Char(char),}fnmain(){println!("{}", std::mem::size_of::<&str>());println!("{}", std::mem::size_of::<Option<&str>>());// current optimizationprintln!("{}", std::mem::size_of::<StrOrChar>());// proposed optimization}
currently prints (on x86_64) 16, 16 and 24. But it could potentially be 16, 16 and 16.
This optimization should be possible if we have an enum with two variants a and b, the a variant contains non-nullable field and the size of a is greater than the size of b (probably size of b should be a divisor of size of a or 0 for alignment).
The text was updated successfully, but these errors were encountered:
ordian
changed the title
Extend the "nullable pointer optimization" to two one-field variants
Extend the "nullable pointer optimization" to two different size variants
Jul 27, 2017
So basically the char would just occupy the same memory as the length field of the slice? I think the example should use a u32, because a char enables so many other optimizations it could cause confusion.
Also I think this needs an RFC. Also note the related RFC issue: rust-lang/rfcs#1230
So basically the char would just occupy the same memory as the length field of the slice? I think the example should use a u32, because a char enables so many other optimizations it could cause confusion.
Play:
currently prints (on x86_64) 16, 16 and 24. But it could potentially be 16, 16 and 16.
This optimization should be possible if we have an enum with two variants
a
andb
, thea
variant contains non-nullable field and the size of a is greater than the size of b (probably size of b should be a divisor of size of a or 0 for alignment).The current "nullable pointer optimization" is a special case with size of b equal to 0.
src link
The text was updated successfully, but these errors were encountered: