copyless icon indicating copy to clipboard operation
copyless copied to clipboard

box! macro?

Open glandium opened this issue 5 years ago • 3 comments

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

glandium avatar Apr 24 '19 09:04 glandium

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

kvark avatar Apr 24 '19 13:04 kvark

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.

Speedy37 avatar Jul 04 '19 12:07 Speedy37

@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

kvark avatar Jul 04 '19 15:07 kvark