Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upsmallvec! macro requires T to be Copy #98
Closed
Comments
|
That seems like a reasonable change. The macro would probably require something like |
RReverser
added a commit
to RReverser/rust-smallvec
that referenced
this issue
Jul 27, 2018
When count of items is smaller or equal than the target inline size, macro will use `SmallVec::push`, but when it's large enough, it passes data on to `vec!` macro for in-place heap allocation and then uses `SmallVec::from_vec`. This trick gives ~3.5x performance increase on `bench_macro_from_list` compared to `SmallVec::with_capacity`. Fixes servo#98.
|
@samnardoni @jdm I made a PR to fix this issue in a relatively performant manner. |
bors-servo
added a commit
that referenced
this issue
Aug 4, 2018
Allow smallvec! with non-Copy items When count of items is smaller or equal than the target inline size, macro will use `SmallVec::push`, but when it's large enough, it passes data on to `vec!` macro for in-place heap allocation and then uses `SmallVec::from_vec`. This trick gives ~3.5x performance increase on `bench_macro_from_list` compared to `SmallVec::with_capacity`. Fixes #98. <!-- 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/107) <!-- Reviewable:end -->
bors-servo
added a commit
that referenced
this issue
Aug 4, 2018
Allow smallvec! with non-Copy items When count of items is smaller or equal than the target inline size, macro will use `SmallVec::push`, but when it's large enough, it passes data on to `vec!` macro for in-place heap allocation and then uses `SmallVec::from_vec`. This trick gives ~3.5x performance increase on `bench_macro_from_list` compared to `SmallVec::with_capacity`. Fixes #98. <!-- 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/107) <!-- Reviewable:end -->
bors-servo
added a commit
that referenced
this issue
Aug 4, 2018
Allow smallvec! with non-Copy items When count of items is smaller or equal than the target inline size, macro will use `SmallVec::push`, but when it's large enough, it passes data on to `vec!` macro for in-place heap allocation and then uses `SmallVec::from_vec`. This trick gives ~3.5x performance increase on `bench_macro_from_list` compared to `SmallVec::with_capacity`. Fixes #98. <!-- 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/107) <!-- Reviewable:end -->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
smallvec!macro, when using thesmallvec![a,b,c]form, requires thatT: Copy.This is because the macro expands to use
SmallVec::from_slice.Perhaps it could instead expand into something like...
... and remove the need for
T: Copy?