Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 4 additions & 53 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,6 @@ use std::slice;
use SmallVecData::{Inline, Heap};


pub trait VecLike<T>:
ops::Index<usize, Output=T> +
ops::IndexMut<usize> +
ops::Index<ops::Range<usize>, Output=[T]> +
ops::IndexMut<ops::Range<usize>> +
ops::Index<ops::RangeFrom<usize>, Output=[T]> +
ops::IndexMut<ops::RangeFrom<usize>> +
ops::Index<ops::RangeTo<usize>, Output=[T]> +
ops::IndexMut<ops::RangeTo<usize>> +
ops::Index<ops::RangeFull, Output=[T]> +
ops::IndexMut<ops::RangeFull> +
ops::Deref +
ops::DerefMut +
Extend<T> {

fn len(&self) -> usize;
fn push(&mut self, value: T);
}

impl<T> VecLike<T> for Vec<T> {
#[inline]
fn len(&self) -> usize {
Vec::len(self)
}

#[inline]
fn push(&mut self, value: T) {
Vec::push(self, value);
}
}

unsafe fn deallocate<T>(ptr: *mut T, capacity: usize) {
let _vec: Vec<T> = Vec::from_raw_parts(ptr, 0, capacity);
// Let it drop.
Expand Down Expand Up @@ -150,12 +119,6 @@ impl<A: Array> SmallVec<A> {
pub fn inline_size(&self) -> usize {
A::size()
}
pub fn len(&self) -> usize {
self.len
}
pub fn is_empty(&self) -> bool {
self.len == 0
}
pub fn capacity(&self) -> usize {
match self.data {
Inline { .. } => A::size(),
Expand Down Expand Up @@ -400,18 +363,6 @@ impl_index!(ops::RangeTo<usize>, [A::Item]);
impl_index!(ops::RangeFull, [A::Item]);


impl<A: Array> VecLike<A::Item> for SmallVec<A> {
#[inline]
fn len(&self) -> usize {
SmallVec::len(self)
}

#[inline]
fn push(&mut self, value: A::Item) {
SmallVec::push(self, value);
}
}

impl<A: Array> FromIterator<A::Item> for SmallVec<A> {
fn from_iter<I: IntoIterator<Item=A::Item>>(iterable: I) -> SmallVec<A> {
let mut v = SmallVec::new();
Expand Down Expand Up @@ -531,11 +482,11 @@ impl<A: Array> Drop for IntoIter<A> {

impl<A: Array> Iterator for IntoIter<A> {
type Item = A::Item;

#[inline]
fn next(&mut self) -> Option<A::Item> {
if self.current == self.end {
None
None
}
else {
unsafe {
Expand All @@ -557,7 +508,7 @@ impl<A: Array> DoubleEndedIterator for IntoIter<A> {
#[inline]
fn next_back(&mut self) -> Option<A::Item> {
if self.current == self.end {
None
None
}
else {
unsafe {
Expand Down Expand Up @@ -794,7 +745,7 @@ pub mod tests {
self.0.set(self.0.get() + 1);
}
}

{
let cell = Cell::new(0);
let mut v: SmallVec<[DropCounter; 2]> = SmallVec::new();
Expand Down