Project

General

Profile

Actions

Feature #294

open

Small string optimization

Added by Eugen Wissner 11 months ago.

Status:
New
Priority:
Normal
% Done:

0%


Description

For tanya.container.string.

The size of the string is currently 3 words, where a word is size_t.sizeof:

  • length
  • capacity
  • 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 (ubyte or 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[22]

Analogous on 32-bit.

No data to display

Actions

Also available in: Atom PDF