You mean small string optimization? Yes, that's nifty. Still, I think it
could be made better.
Current mainstream (64-bit) implementations use SSO buffer of 16 bytes.
However, when a string is used inside an union which is larger, it could
well use a larger buffer, but there is no way to set this up.
A polymorphic variant class which I once made is 24 bytes. The last byte
in the class is the variant type tag, which is chosen to be 0 for small
strings, so that I can store zero-terminated small UTF-8 strings of up
to 23 bytes in it. I do not record the string length separately for
small strings as it is cheap to just calculate it by strlen() whenever
needed.