stdio performance in tango, stdlib, and perl

Vladimir Panteleev thecybershadow at gmail.com
Thu Mar 22 04:31:54 PDT 2007


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.

> 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 :)

-- 
Best regards,
  Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list