You can use Folly’s trick to fit one more character in the small string. Invert the flag bit so zero = small string, and store it in the last byte, along with the small length stored as 15-len. Then, the full 16 bytes can be used for a small string since the final byte simultaneously acts as the type/length byte AND the null terminator when the string length is 15.
The big strings aren't NUL-terminated, so there's no point in doing that for the small ones. Folly devs went to great (crazy) lengths to avoid '\0' too, unsuccessfully. Their hands were tied by the standard, I don't have such constraints.
View all comments
7
u/kevkevverson 11d ago
You can use Folly’s trick to fit one more character in the small string. Invert the flag bit so zero = small string, and store it in the last byte, along with the small length stored as 15-len. Then, the full 16 bytes can be used for a small string since the final byte simultaneously acts as the type/length byte AND the null terminator when the string length is 15.