Small string optimization
The size of the string is currently 3 words, where a word is
- data pointer
Short string should have the same size.
Whether the string is in short or long format can be stored as a flag in the MSB of the length.
The short string requires only 7 bits for the length and 1 bit for the flag (
byte). It should also keep one byte free for \0', so toStringz can return a null-terminated string without allocating. The remaining bits can be used for the static storage.
On 64-bit 3 words are
8 * 3 = 24 bytes:
- 1 bit - flag
- 7 bits - length
- 8 bits - '\0'
- 22 bytes - char
Analogous on 32-bit.
No data to display