-
Notifications
You must be signed in to change notification settings - Fork 150
Add HeapSizeOf trait and from_slice method #42
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
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it just be impl<A: Array, T: AsRef<[A::Item]>> From<T> for SmallVec<A>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
lib.rs
Outdated
@@ -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)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I was playing around with specialization and accidentally rolled it into this. Fixed!
@bors-servo: r+ |
📌 Commit 010df90 has been approved by |
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 -->
☀️ Test successful - status-travis |
Thanks yo! |
Also added some tests for the new methods. The rationale
This change is