maplit icon indicating copy to clipboard operation
maplit copied to clipboard

Macro for VecDeque

Open sunjay opened this issue 8 years ago • 10 comments

Would it be possible to add a macro similar to vec! but for VecDeque instead?

sunjay avatar Feb 27 '17 22:02 sunjay

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.

bluss avatar Feb 27 '17 22:02 bluss

Could the macro expand to use with_capacity() and push()?

sunjay avatar Feb 27 '17 23:02 sunjay

Yes I think so. I guess using vec![] is sometimes more ideal, but users can then use that.

bluss avatar Feb 27 '17 23:02 bluss

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.

sunjay avatar Feb 27 '17 23:02 sunjay

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.

bluss avatar Feb 27 '17 23:02 bluss

I have an implementation based on with_capacity() and push_back(). Would a PR be welcome?

Nokel81 avatar Mar 05 '19 22:03 Nokel81

@Nokel81 Yes, please :)

Boscop avatar Mar 11 '20 05:03 Boscop

#31

Nokel81 avatar Mar 11 '20 17:03 Nokel81

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?

justin13888 avatar Dec 30 '23 23:12 justin13888

What's status for this feature request?

gamedev-pnc avatar Jun 08 '24 20:06 gamedev-pnc