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: On Clone, eagerly inline based on length not capacity #257

Closed ParkMyCar closed 1 year ago

ParkMyCar commented 1 year ago

In #254 we began inlining CompactStrings when Clone-ing, if the capacity of the CompactString was less than MAX_SIZE. This made sure we retained any additional capacity a user may have allocated.

During some experimentation though, I realized String truncates capacity during clone, example.

As such this PR updates the eager inlining during Clone to instead be based on the source CompactString's length, which. This allows us to more frequently inline strings, and follows the same behavior as String.