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 upAdd HeapSizeOf trait and from_slice method #42
Conversation
Because it seems like good practice.
| @@ -478,6 +482,12 @@ impl<A: Array> SmallVec<A> { | |||
| } | |||
|
|
|||
| impl<A: Array> SmallVec<A> where A::Item: Copy { | |||
| pub fn from_slice(slice: &[A::Item]) -> Self { | |||
This comment has been minimized.
This comment has been minimized.
rphmeier
Mar 14, 2017
Contributor
Could it just be impl<A: Array, T: AsRef<[A::Item]>> From<T> for SmallVec<A>?
This comment has been minimized.
This comment has been minimized.
nipunn1313
Mar 15, 2017
Author
Contributor
Also need to make sure A::Item: Copy which is what made me make it more specific (from_slice() rather than impl From).
I'd imagine that a generic From implementation should work regardless of whether it's Copy or not. Without specialization, it's hard to make an efficient version for the Copy type, so I went with a different "from_slice" function.
|
For the record |
|
@tomaka That can be addressed by putting heapsize stuff under a feature flag |
|
Let's have an optional feature flag for heapsize, as mentioned in previous comments. Otherwise these changes look unobjectionable to me. |
| @@ -6,6 +6,9 @@ | |||
| //! to the heap for larger allocations. This can be a useful optimization for improving cache | |||
| //! locality and reducing allocator traffic for workloads that fit within the inline buffer. | |||
|
|
|||
| #![feature(specialization)] | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nipunn1313
Mar 16, 2017
Author
Contributor
Good catch. I was playing around with specialization and accidentally rolled it into this. Fixed!
|
@bors-servo: r+ |
|
|
Add HeapSizeOf trait and from_slice method Also added some tests for the new methods. The rationale - from_slice is an ergonomic way to convert a Copy-able slice to a SmallVec (instead of using the From<'a slice> which uses an iterator) - HeapSizeOf is handy for measuring heap allocations. Especially useful for monitoring something like this. Seems to be part of the servo project anyway. - Added size 36 to smallvec sizes (was useful to us) <!-- 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/42) <!-- Reviewable:end -->
|
|
|
Thanks yo! |
nipunn1313 commentedMar 14, 2017
•
edited
Also added some tests for the new methods. The rationale
This change is