Skip to content

Commit ee5fe38

Browse files
author
bors-servo
authored
Auto merge of #123 - llogiq:specialization, r=nox
First specialization I added a new `specialization` feature that will specialize `From<&[_: Copy]>` to use `from_slice`, which offers a nice performance boost. Alas, I could not get any measurable perf improvement on `insert_many` or `extend` yet, so I'll leave them out for now. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/123) <!-- Reviewable:end -->
2 parents 65f72d1 + 49c43d0 commit ee5fe38

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ documentation = "http://doc.servo.org/smallvec/"
1414
std = []
1515
union = []
1616
default = ["std"]
17+
specialization = []
1718

1819
[lib]
1920
name = "smallvec"

lib.rs

+30
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![cfg_attr(not(feature = "std"), no_std)]
3232
#![cfg_attr(not(feature = "std"), feature(alloc))]
3333
#![cfg_attr(feature = "union", feature(untagged_unions))]
34+
#![cfg_attr(feature = "specialization", feature(specialization))]
3435
#![deny(missing_docs)]
3536

3637

@@ -1156,11 +1157,40 @@ where A::Item: Deserialize<'de>,
11561157
}
11571158
}
11581159

1160+
1161+
#[cfg(feature = "specialization")]
1162+
trait SpecFrom<A: Array, S> {
1163+
fn spec_from(slice: S) -> SmallVec<A>;
1164+
}
1165+
1166+
#[cfg(feature = "specialization")]
1167+
impl<'a, A: Array> SpecFrom<A, &'a [A::Item]> for SmallVec<A> where A::Item: Clone {
1168+
#[inline]
1169+
default fn spec_from(slice: &'a [A::Item]) -> SmallVec<A> {
1170+
slice.into_iter().cloned().collect()
1171+
}
1172+
}
1173+
1174+
#[cfg(feature = "specialization")]
1175+
impl<'a, A: Array> SpecFrom<A, &'a [A::Item]> for SmallVec<A> where A::Item: Copy {
1176+
#[inline]
1177+
fn spec_from(slice: &'a [A::Item]) -> SmallVec<A> {
1178+
SmallVec::from_slice(slice)
1179+
}
1180+
}
1181+
11591182
impl<'a, A: Array> From<&'a [A::Item]> for SmallVec<A> where A::Item: Clone {
1183+
#[cfg(not(feature = "specialization"))]
11601184
#[inline]
11611185
fn from(slice: &'a [A::Item]) -> SmallVec<A> {
11621186
slice.into_iter().cloned().collect()
11631187
}
1188+
1189+
#[cfg(feature = "specialization")]
1190+
#[inline]
1191+
fn from(slice: &'a [A::Item]) -> SmallVec<A> {
1192+
SmallVec::spec_from(slice)
1193+
}
11641194
}
11651195

11661196
impl<A: Array> From<Vec<A::Item>> for SmallVec<A> {

0 commit comments

Comments
 (0)