Get length.
Get slice.
Get pointer to characters.
Number of bits used to memory address.
Number of bits used to store length. 2024-01-01: Address space of a single Linux user process is 47 bits.
Capacity of small variant where length fits in lengthBits.
Bit mask of address part.
Bit mask of length part.
const s = "alpha"; PackedString p = s; assert(p.ptr == s.ptr); assert(p.length == s.length); assert(p[] == s); assert(p == s);
string s; s.length = PackedString.smallCapacity; PackedString p = s; assert(p.ptr == s.ptr); assert(p.length == s.length); assert(p[] == s); assert(p == s); assert(p is s);
String packed into one word.
Length is stored in upper lengthBits of pointer/word _raw.
All length bits set means memory bits of _raw points to string. This makes PackedString nothrow.
TODO: If D's GC doesn't ignore the upper lengthBits bits of pointer, make core.memory.GC be told that every PackedString should be bit-anded with addressMask before scanned for an address. Related functions: - isLarge.
Proposed API for specifying this is: `__traits(adressBitMask, declaration, mask) where declaration.sizeof == size_t.sizeof`.