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:
root
2015-05-20 17:17:17 +02:00
parent 5b916cab16
commit 8730a3584b
+19 -1
View File
@@ -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.
pub struct ArrayVec<A: Array> {
len: u8,
xs: Flag<A>,
len: u8,
}
impl<A: Array> Drop for ArrayVec<A> {
@@ -537,3 +537,21 @@ fn test_is_send_sync() {
&data as &Send;
&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);
}