[Issue 15293] [REG2.069.0] std.stdio.readln(buffer) messes up buffer's capacity
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Nov 12 08:25:30 PST 2015
https://issues.dlang.org/show_bug.cgi?id=15293
--- Comment #9 from Steven Schveighoffer <schveiguy at yahoo.com> ---
The behavior is expected, and actually intentional.
The original behavior was that regardless of current capacity, if a GC buffer
was passed, ALL the space was claimed by readln.
In this case, what is passed is not a buffer that ends on an appendable
boundary, and so it chooses to do nothing as far as updating the appendability
(the right choice).
The reason it was done this way is to allow for a common usage of readln
(namely, reading into a buffer over and over again) to continue to have good
performance. If we took the "safe" route (and believe me, it was debated and
considered), then this code would reallocate every time a larger line was read.
When it was originally written, this is what byLine did, but now it's changed.
> The other readlnImpl variants don't work like that
looking at it now, the other variants do exactly as I said above -- they
reallocate when the line is longer.
So technically we could move to this, we just have to accept a drop in
performance for the code.
Have you tested the performance of your new code vs. the current
implementation?
--
More information about the Digitalmars-d-bugs
mailing list