SSOString

Small-size-optimized (SSO) variant of string.

Storage is placed on the stack if the number of chars is less than smallCapacity, otherwise as a normal (large) string. The large string will be allocated on the GC-heap if the SSOString is constructed from a non-string (non-immutable char[]) parameter.

Because SSOString doesn't have a destructor it can safely allocate using a GC-backed region allocator without relying on a GC finalizer.

In order to mimic string/array/slice-behaviour, opCast returns false for SSOString() and true for SSOString(""). This requires SSOString() to default to a large string in which large pointer is set to null.

Big-endian platform support hasn't been verified.

Constructors

this
this(Chars source)

Construct from source, which potentially needs GC-allocation (iff source.length > smallCapacity and source is not a string).

this
this(Source source)

Construct from source of dchar

Members

Aliases

opDollar
alias opDollar = length

Get length.

Functions

empty
bool empty()

Check if this is empty.

holeify
void holeify()

That this a hole, meaning a removed/erase value.

isHole
bool isHole()

Check if this a hole, meaning a removed/erase value.

isNull
bool isNull()

Check if this is null.

isSmallASCII
bool isSmallASCII()

Check if this is a small ASCII string.

length
size_t length()

Get length.

opCmp
int opCmp(typeof(this) that)

Compare this with that.

opEquals
bool opEquals(typeof(this) rhs)

Check if this is equal to rhs.

opEquals
bool opEquals(const(char)[] rhs)

Check if this is equal to rhs.

opIndex
inout(char) opIndex(size_t index)

Return the indexed char of this.

opSlice
inout(char)[] opSlice()

Return a slice to either the whole large or whole small string.

opSlice
inout(char)[] opSlice(size_t i, size_t j)

Return a slice at [i .. j] to either the internally stored large or small string.

toHash
hash_t toHash()

Get hash of this, with extra fast computation for the small case.

toString
string toString()

Return this converted to a string, without any GC-allocation because this is immutable.

toString
string toString()

Return this converted to a string, which potentially needs GC-allocation (iff length > smallCapacity).

Static variables

holeValue
auto holeValue;

Support trait isHoleable.

nullValue
auto nullValue;

Support trait isNullable.

See Also

https://forum.dlang.org/post/pb87rn$2icb$1@digitalmars.com https://issues.dlang.org/show_bug.cgi?id=18792

https://forum.dlang.org/post/agzznbzkacfhyqvoezht@forum.dlang.org

TODO Use extra bits in Short.length for these special text encodings: - 5-bit lowercase English letter into 128/5 = 25 chars - 5-bit uppercase English letter into 120/5 = 25 chars - 6-bit mixedcase English letter into 120/6 = 20 chars

TODO Add to Phobos' std.typecons or std.array or std.string

Meta