This commit is contained in:
root
2015-05-19 17:04:04 +02:00
parent 55612bcae8
commit f5da5c9fe2
+6 -7
View File
@@ -7,7 +7,6 @@ use std::ops::{
use std::slice; use std::slice;
use std::convert::From; use std::convert::From;
/// Make sure the non-nullable pointer optimization does not occur! /// Make sure the non-nullable pointer optimization does not occur!
enum Flag<T> { enum Flag<T> {
Alive(T), Alive(T),
@@ -17,7 +16,7 @@ enum Flag<T> {
/// Trait for fixed size arrays. /// Trait for fixed size arrays.
pub unsafe trait Array { pub unsafe trait Array {
#[doc(hidden)] /// The array's element type
type Item; type Item;
#[doc(hidden)] #[doc(hidden)]
unsafe fn new() -> Self; unsafe fn new() -> Self;
@@ -94,7 +93,7 @@ impl<A: Array> ArrayVec<A> {
/// ## Examples /// ## Examples
/// ///
/// ``` /// ```
/// use arrayvec::ArrayVec; /// use arrayvec::ArrayVec;
/// ///
/// let mut array = ArrayVec::<[_; 16]>::new(); /// let mut array = ArrayVec::<[_; 16]>::new();
/// array.push(1); /// array.push(1);
@@ -109,7 +108,7 @@ impl<A: Array> ArrayVec<A> {
} }
#[inline] #[inline]
fn array(&self) -> &A { fn inner_ref(&self) -> &A {
match self.xs { match self.xs {
Flag::Alive(ref xs) => xs, Flag::Alive(ref xs) => xs,
_ => unreachable!(), _ => unreachable!(),
@@ -118,7 +117,7 @@ impl<A: Array> ArrayVec<A> {
} }
#[inline] #[inline]
fn array_mut(&mut self) -> &mut A { fn inner_mut(&mut self) -> &mut A {
// FIXME: Optimize this, we know it's always Some. // FIXME: Optimize this, we know it's always Some.
match self.xs { match self.xs {
Flag::Alive(ref mut xs) => xs, Flag::Alive(ref mut xs) => xs,
@@ -216,7 +215,7 @@ impl<A: Array> Deref for ArrayVec<A> {
#[inline] #[inline]
fn deref(&self) -> &[A::Item] { fn deref(&self) -> &[A::Item] {
unsafe { unsafe {
slice::from_raw_parts(self.array().as_ptr(), self.len()) slice::from_raw_parts(self.inner_ref().as_ptr(), self.len())
} }
} }
} }
@@ -226,7 +225,7 @@ impl<A: Array> DerefMut for ArrayVec<A> {
fn deref_mut(&mut self) -> &mut [A::Item] { fn deref_mut(&mut self) -> &mut [A::Item] {
let len = self.len(); let len = self.len();
unsafe { unsafe {
slice::from_raw_parts_mut(self.array_mut().as_mut_ptr(), len) slice::from_raw_parts_mut(self.inner_mut().as_mut_ptr(), len)
} }
} }
} }