typst / ecow

Compact, clone-on-write vector and string.
Apache License 2.0
205 stars 16 forks source link

Support some of the unstable/unsafe features from `std::Vec` #40

Open Oppen opened 5 months ago

Oppen commented 5 months ago

It would be nice if the API mapped closer to std::Vec. Methods like assume_init or set_len or the ability to use custom allocators are used in a project for which EcoVec is otherwise a perfect fit to reduce memory fragmentation.

laurmaedje commented 4 months ago

I'm open to exposing more low-level methods in principle. However, we need to be very careful in cases where ecow needs extra guarantees. Especially things like set_len which require the user to reason about the internal state of the Vec are a bit trickier since the EcoVec may perform clone-on-write, which for instance can change its capacity. Regarding the other mentioned one: I can't find an assume_init method for std::vec::Vec.

Oppen commented 4 months ago

assume_init is part of MaybeUninit, more related to the Arc-like characteristics. I guess with set_len and by using the spare capacity you get equivalent dynamics as with assume_init in an uninitialized slice.

laurmaedje commented 4 months ago

I'm not yet entirely sure how the assume_init thing would look like. But it's also nightly-only in Rust, so maybe a bit early.