ParkMyCar / compact_str

A memory efficient string type that can store up to 24* bytes on the stack
MIT License
652 stars 47 forks source link

api: Update From<String> and From<Box<str>> to eagerly inline #256

Closed ParkMyCar closed 1 year ago

ParkMyCar commented 1 year ago

Currently when converting from a String to a CompactString using From<String> (also for Box<str>) we wouldn't inline short strings, this was to avoid needing to de-allocate the original String. After some feedback collected in #227 we realized while this was performant, it's not what most users expect to happen.

This PR updates the implementation of From<String> and From<Box<str>> to inline short strings, and it adds a new API CompactStr::from_string_buffer, which retains the current behavior of always re-using the underlying buffer. Note, in #254 we implemented inline-ing during Clone, so even if you use from_string_buffer, future short strings should get inlined.

Fixes #227