stdio performance in tango, stdlib, and perl
Daniel Keep
daniel.keep.lists at gmail.com
Thu Mar 22 05:28:36 PDT 2007
Vladimir Panteleev wrote:
> On Thu, 22 Mar 2007 11:03:12 +0200, Daniel Keep <daniel.keep.lists at gmail.com> wrote:
>
>>> 4) it's much easier to add a line ending than to remove it.
>> Actually, it's not. Removing a line ending is as simple as slicing the
>> string. *Adding* a line ending could involve a heap allocation, at
>> least a full copy.
>
> I was actually talking about the complexity of the source, not the efficiency of the generated code.
> When readln gives you the line with a line ending, you have three cases:
> 1) a CR/LF line ending (Windows)
> 2) LF line ending (Unix)
> 3) no line ending at all (EOF)
>
> You'd need to account for every of these when removing the line endings - and write this code every time you're writing an app which just needs the contents of lines from standard input - which, as you have agreed, is quite common.
import std.string;
auto line = readln().chomp();
:)
>> What's more, how can you be sure there was a line-ending there at all?
>> What if it's the last line and it didn't have a line ending before EOF?
>
> IMHO, most tools which work with standard input don't really need to know if the last line has a line break at the end :)
>
--
int getRandomNumber()
{
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
http://xkcd.com/
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list