copy only reference rather duplicate a string in appender!string
Neia Neutuladh
neia at ikeran.org
Tue Dec 26 17:25:45 UTC 2017
On Tuesday, 26 December 2017 at 15:37:12 UTC, Marc wrote:
> I do build a string by coping large parts of diffrent buffers,
> all those buffers live after the functional call, so rather
> than duplicate those string I'd like to copy only references to
> those parts rather duplicate every string. I combined
> appender!string, assumeUnique() and array slices. Something
> like this:
This depends on whether you have several variables as buffers or
an array of buffers.
With several variables:
http://dpldocs.info/experimental-docs/std.range.chain.html
With an array, or something else iterable:
http://dpldocs.info/experimental-docs/std.algorithm.iteration.joiner.2.html
So you can use:
chain(buf1, buf2, buf3);
Or:
myBuffers = [buf1, buf2, buf3];
joiner(myBuffers);
That produces something string-like. (A rope, but with a poor
API.) You can iterate through it as a string, you can output it
to a file, etc. You can't pass it to something that expects a
string specifically; for instance, you can't return that from
`MyClass.toString()`.
More information about the Digitalmars-d-learn
mailing list