kvark/copyless

box! macro?

glandium opened this issue · 3 comments

It feels like there could be a box! macro that would do Box::alloc().init(...).

kvark commented

There could be, yeah. I have a slight preference of not introducing macros unless necessary.

It looks like creating a Box::new method that use Box::alloc().init() is still copyless: https://rust.godbolt.org/z/GyAohL

There is probably something to be done in std to get the optimization without much troubles.

Edit: just did the same test with Vec, without success.

kvark commented

@Speedy37 we looked at your (interesting!) case and realized that the check for NULL returned by alloc() was missing in the version of code you copied.
The fixed version (that is in master and 0.1.4) makes new_fast not feasible any more: https://rust.godbolt.org/z/JgOjcn