[Dlang-study] [rcstring] Defining rcstring
Andrei Alexandrescu
andrei at erdani.com
Tue Feb 2 13:40:26 PST 2016
Hello everyone,
Let's reboot this list with a simpler discussion: rcstring, a
reference-counted string. My initial thoughts:
* make it part of a nascent std.experimental.lifetime module/package
* call it rcstring or RCString? The first makes it closer to "string",
the other is politically correct.
* Characters are small so no need to return them by reference. Because
of this, making RCString @safe should be possible in current D. However,
this also makes RCString not a plug-in replacement for string (which may
after all be a good thing)
* Since string-compatibility is off the table, how about we fix string's
issues with autodecoding? RCString should offer no indexed access and no
length. Instead it offers the ranges byCodeUnit, byChar, byWChar, and
byDChar. The first one does not do any decoding and offers length and
random access. (What should be its element type?) The other ones are
bidirectional ranges that do the appropriate decoding.
* Immutable does not play well with reference counting. I'm of a mind to
reject immutable rcstring for now and figure out later how to go about
it. Then const rcstring is okay because we always consider const a view
on mutable strings (even though they're gone). We'll cast const away
when manipulating the refcount.
* I don't have the small string optimization implemented yet, but
obviously the definition of the type should allow it.
Thoughts?
Andrei
More information about the Dlang-study
mailing list