Skip to content

Commit

Permalink
add proper smallvec support
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed Aug 23, 2016
1 parent 3e3e18f commit 697ec9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "insert_many"
version = "0.1.0"
version = "0.1.1"
authors = ["Robert Habermeier <[email protected]>"]
description = "insert_many optimization for vec-like structures"
license = "MIT"
Expand All @@ -10,4 +10,4 @@ repository = "https://github.com/rphmeier/insert_many.git"
smallvec = { version = "0.2.0", optional = true }

[features]
default = ["smallvec"]
default = ["smallvec"]
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
//! Like `Vec::insert`, but inserts a series of items at an index rather than a single one.
//! This can lead to significant speedup where multiple items need to be inserted.
#[cfg(features = "smallvec")]
#[cfg(feature = "smallvec")]
extern crate smallvec;

use std::iter::ExactSizeIterator;
use std::ptr;

use smallvec::SmallVec;

/// Generalized trait for inserting many items at once.
pub trait InsertMany<T> {
/// Insert all the items in the given iterable at `index`, shifting all elements after it to the right.
Expand Down Expand Up @@ -52,7 +54,7 @@ impl<T> InsertMany<T> for Vec<T> {
}
}

#[cfg(features = "smallvec")]
#[cfg(feature = "smallvec")]
impl<A: smallvec::Array> InsertMany<A::Item> for SmallVec<A> {
fn insert_many<I>(&mut self, index: usize, iterable: I) where I: IntoIterator<Item=A::Item>, I::IntoIter: ExactSizeIterator {
impl_veclike!(self, index, iterable);
Expand Down Expand Up @@ -80,4 +82,4 @@ mod tests {

assert_eq!(v, vec![1, 2, 3, 4, 5, 6, 7, 8, 9]);
}
}
}

0 comments on commit 697ec9f

Please sign in to comment.