PackedString

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`.

Constructors

this
this(string x)
Undocumented in source.

Alias This

opSlice

Members

Aliases

Large
alias Large = immutable(char)[]
Undocumented in source.

Functions

length
size_t length()

Get length.

opSlice
string opSlice()

Get slice.

ptr
immutable(char)* ptr()

Get pointer to characters.

toString
void toString(Sink sink)
Undocumented in source. Be warned that the author may not have intended to support it.

Manifest constants

addressBits
enum addressBits;

Number of bits used to memory address.

lengthBits
enum lengthBits;

Number of bits used to store length. 2024-01-01: Address space of a single Linux user process is 47 bits.

smallCapacity
enum smallCapacity;

Capacity of small variant where length fits in lengthBits.

totalBits
enum totalBits;
Undocumented in source.

Properties

isLarge
bool isLarge [@property getter]

Variables

addressMask
enum size_t addressMask;

Bit mask of address part.

lengthMask
enum size_t lengthMask;

Bit mask of length part.

Examples

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);

Meta