RCXString

Reference Counted Array. Configured with character type E, maximum length for the small string optimization, and the allocation function, which must have the same semantics as realloc.

Constructors

this
this(C[] s)

Construct a RCXString from a slice s.

Destructor

~this
~this()
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Aliases

opDollar
alias opDollar = length

Returns the length of the string

Functions

back
dchar back()

Returns the last code point of this.

back
E back()
Undocumented in source.
capacity
size_t capacity()

Returns the maximum number of character this string can store without requesting more memory.

empty
bool empty()

Returns true iff this is empty

front
auto front()

Returns the first code point of this.

length
size_t length()

Returns the length of the string

opAssign
void opAssign(immutable(ME)[] s)
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
void opAssign(const(ME)[] s)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
RCXString opBinary(RCXString s)
RCXString opBinary(const(ME)[] s)

Returns the concatenation of this with s.

opBinaryRight
RCXString opBinaryRight(const(E)[] s)

Returns the concatenation of s with this.

opEquals
bool opEquals(const(ME)[] s)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(RCXString s)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
E opIndex(size_t n)

Returns the nth code unit in this.

opOpAssign
void opOpAssign(const(ME)[] s)
void opOpAssign(RCXString s)

Appends s to this.

opSlice
auto opSlice()
auto opSlice(size_t b, size_t e)

Returns a slice to the entire string or a portion of it.

popBack
void popBack()

Discards the last code point

popFront
void popFront()

Discards the first code point

ptr
auto ptr()
Undocumented in source. Be warned that the author may not have intended to support it.
reserve
void reserve(size_t capacity)
Undocumented in source. Be warned that the author may not have intended to support it.
toArray
string toArray()

Needed for correct printing in other modules

Manifest constants

maxSmallLength
enum maxSmallLength;
Undocumented in source.

Examples

verify UTF-8 storage

string s = "åäö";
RCString rcs = s;
assert(rcs.length == 6);
import std.algorithm : count;
assert(rcs.count == 3);
assert(rcs.front == 'å');
rcs.popFront();
assert(rcs.front == 'ä');
rcs.popFront();
assert(rcs.front == 'ö');
rcs.popFront();
assert(rcs.empty);

shows performance increase for SSO over built-in string

enum maxSmallSize = 23;
alias S = RCXString!(immutable char, maxSmallSize);

import std.datetime: StopWatch, Duration;
import std.conv : to;
import std.stdio;

enum n = 2^^21;

StopWatch sw;

sw.reset;
sw.start;
char[maxSmallSize] ss;
foreach (i; 0 .. n)
{
	auto x = S(ss);
}
sw.stop;
auto timeRCString = sw.peek().msecs;
writeln("> RCString took ", sw.peek().to!Duration);

sw.reset;
sw.start;
foreach (i; 0 .. n)
{
	string x = ss.idup;
}
sw.stop;
auto timeString = sw.peek().msecs;
writeln("> Builtin string took ", sw.peek().to!Duration);

writeln("> Speedup: ", timeString/timeRCString);

See Also

Meta