DFortune

Unix fortune-cookie parser written in D
git clone git://xatko.vsos.ethz.ch/DFortune.git
Log | Files | Refs

commit 9b96f60c0691e4fb488ea6d9c7856961d5a0ee0f
parent 3c94880ac4d1aedd042a12e915d314790f2a88b8
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Sun,  9 Aug 2015 14:31:55 +0200

Preallocate conversion buffer.

Diffstat:
dfortune.d | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/dfortune.d b/dfortune.d @@ -88,15 +88,17 @@ class Fortune : RandomAccessFinite!(string){ if(src==dst){ return cast(string) buf; } + char str[]; + str.reserve(buf.length); const(ubyte)[] derp=buf; - while(derp.length>0){ ubyte bufbuf[4]; ubyte written; written=cast(ubyte)dst.encode(src.safeDecode(derp),bufbuf); str~=bufbuf[0..written]; } + return cast(string)str; }