Merge pull request #71 from clarcharr/master
Make zero-capacity ArrayVec a zero-sized type.
This commit is contained in:
+18
-1
@@ -44,6 +44,20 @@ pub trait ArrayExt : Array {
|
|||||||
|
|
||||||
impl<A> ArrayExt for A where A: Array { }
|
impl<A> ArrayExt for A where A: Array { }
|
||||||
|
|
||||||
|
impl Index for () {
|
||||||
|
#[inline(always)]
|
||||||
|
fn to_usize(self) -> usize { 0 }
|
||||||
|
#[inline(always)]
|
||||||
|
fn from(ix: usize) -> Self { () }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Index for bool {
|
||||||
|
#[inline(always)]
|
||||||
|
fn to_usize(self) -> usize { self as usize }
|
||||||
|
#[inline(always)]
|
||||||
|
fn from(ix: usize) -> Self { ix != 0 }
|
||||||
|
}
|
||||||
|
|
||||||
impl Index for u8 {
|
impl Index for u8 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_usize(self) -> usize { self as usize }
|
fn to_usize(self) -> usize { self as usize }
|
||||||
@@ -97,7 +111,10 @@ macro_rules! fix_array_impl_recursive {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fix_array_impl_recursive!(u8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
||||||
|
fix_array_impl_recursive!((), 0,);
|
||||||
|
fix_array_impl_recursive!(bool, 1,);
|
||||||
|
fix_array_impl_recursive!(u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||||
28, 29, 30, 31, );
|
28, 29, 30, 31, );
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,11 @@ fn test_compact_size() {
|
|||||||
println!("{}", mem::size_of::<ByteArray>());
|
println!("{}", mem::size_of::<ByteArray>());
|
||||||
assert!(mem::size_of::<ByteArray>() <= 8);
|
assert!(mem::size_of::<ByteArray>() <= 8);
|
||||||
|
|
||||||
|
// 1 enum tag + 1 drop flag
|
||||||
|
type EmptyArray = ArrayVec<[u8; 0]>;
|
||||||
|
println!("{}", mem::size_of::<EmptyArray>());
|
||||||
|
assert!(mem::size_of::<EmptyArray>() <= 2);
|
||||||
|
|
||||||
// 12 element size + 1 enum tag + 3 padding + 1 len + 1 drop flag + 2 padding
|
// 12 element size + 1 enum tag + 3 padding + 1 len + 1 drop flag + 2 padding
|
||||||
type QuadArray = ArrayVec<[u32; 3]>;
|
type QuadArray = ArrayVec<[u32; 3]>;
|
||||||
println!("{}", mem::size_of::<QuadArray>());
|
println!("{}", mem::size_of::<QuadArray>());
|
||||||
|
|||||||
Reference in New Issue
Block a user