pchampin / mownstr

MownStr: Maybe Owned String
1 stars 2 forks source link

Optimize for small strings? #4

Closed pchampin closed 1 month ago

pchampin commented 9 months ago

Inspired by what is done in EcoString, MownStr could sacrifice one more bit in the len metadata to "internalize" small (≤15B) strings.

More precisely:

NB: this makes the assumption that xlen and addr are 64bits long... the code would actually need to be adapted for other architectures.

Maybe that's overly complicated for the potential benefit...

pchampin commented 1 month ago

thinking more about this, I'm reluctant to make that change. It requires to know precisely the layout of the internal struct (is the len stored before or after the pointer physically?), the endian-ness of usize (is the most significant bit really at the "beginning" of the usize?)...

And the recent experience with debugging UB (#5, #8) makes me wary of making the code more complex.