Move len last in the struct
Put len last so that it sits next to the drop flag (as of current rust) which saves padding for element types with size_of > 1.
This commit is contained in:
+19
-1
@@ -77,8 +77,8 @@ fix_array_impl_recursive!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|||||||
///
|
///
|
||||||
/// The vector also implements a by value iterator.
|
/// The vector also implements a by value iterator.
|
||||||
pub struct ArrayVec<A: Array> {
|
pub struct ArrayVec<A: Array> {
|
||||||
len: u8,
|
|
||||||
xs: Flag<A>,
|
xs: Flag<A>,
|
||||||
|
len: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Array> Drop for ArrayVec<A> {
|
impl<A: Array> Drop for ArrayVec<A> {
|
||||||
@@ -537,3 +537,21 @@ fn test_is_send_sync() {
|
|||||||
&data as &Send;
|
&data as &Send;
|
||||||
&data as &Sync;
|
&data as &Sync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_no_nonnullable_opt() {
|
||||||
|
// Make sure `Flag` does not apply the non-nullable pointer optimization
|
||||||
|
// as Option would do.
|
||||||
|
assert!(mem::size_of::<Flag<&()>>() > mem::size_of::<&()>());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_compact_size() {
|
||||||
|
// 4 elements size + 1 len + 1 enum tag + [1 drop flag]
|
||||||
|
type ByteArray = ArrayVec<[u8; 4]>;
|
||||||
|
assert!(mem::size_of::<ByteArray>() <= 7);
|
||||||
|
|
||||||
|
// 12 element size + 1 len + 1 drop flag + 2 padding + 1 enum tag + 3 padding
|
||||||
|
type QuadArray = ArrayVec<[u32; 3]>;
|
||||||
|
assert!(mem::size_of::<QuadArray>() <= 20);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user