Skip to content

Remove unnecessary VecLike trait. #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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
@@ -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.
@@ -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(),
@@ -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();
@@ -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 {
@@ -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 {
@@ -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();