Open sunjay opened 7 years ago
Yeah, why not.
VecDeque::from(vec![1, 2, 3])
is not actually cost free, the conversion needs to realloc it to a power of two (which the vec's capacity is not necessarily). So the goal of the macro must be to be better than that somehow.
Could the macro expand to use with_capacity()
and push()
?
Yes I think so. I guess using vec![] is sometimes more ideal, but users can then use that.
This is the source for vec!
: https://github.com/rust-lang/rust/blob/master/src/libcollections/macros.rs
If I'm understanding it correctly, it seems to be using some unstable features.
right, it's using the placement box stuff. It is really ideal to do it like that for vec![]
but for vecdeque it makes an allocation that is (possibly) too small. Maybe I should look at the table of allocation size buckets again and see how they are spread.
I have an implementation based on with_capacity()
and push_back()
. Would a PR be welcome?
@Nokel81 Yes, please :)
I know this thread has been open for a few years but wondering if this functionality was ever merged or should this issue still be open?
What's status for this feature request?
Would it be possible to add a macro similar to
vec!
but for VecDeque instead?