Closed bluss closed 8 years ago
Oh, since this is used in new/with_capacity, it should speed up initial creation of the buf reader pretty significantly.
I don't like .resize()
because it uses .reserve()
internally, which allocates in powers of two. That's great for frequent growth but it seems too greedy in this case. Calling .shrink_to_fit()
afterwards is even more wasteful as it causes another reallocation.
If the iterator-based zeroing isn't generating good code, we can manually lower to a call to .set_len()
and ptr::write_bytes()
at the cost of adding more unsafe
blocks.
It's too bad there's no way to directly call calloc
without reinventing a lot of the wheel.
Or is getting rid of the powers-of-two allocation totally misguided?
There's just a small misunderstanding: reserve only allocates if you need more space -- since you reserve enough upfront you are fine. .extend()
will use reserve
as well, yet it does nothing in this case for the same reason.
See, that's the part I missed. Yeah, sounds fine to me. I'll patch it in right now.
FIxed in 0.1.3
On line https://github.com/cybergeek94/buf_redux/blob/07bc5f90bb7ead27853f86349a6a999c7e931229/src/lib.rs#L129 you can use vec.resize instead, to grow & fill by zeros. It generates much better code.