On 3/20/2015 2:04 PM, Paulo Pinto wrote:
The side effect is not keeping the string, rather generating it.

for var in exp:
    do_something()

if exp represents a iteratable or a generator, even if var is thrown away the
loop needs to be preserved to keep the semantics of calling next() on the
instance object that executes the for..in loop.

Put other way, does DMD throw away foreach loops even if the compiler cannot
prove if  opApply () or popFront() generate side effects, assuming the variable
isn't being used?

D has pure functions, and if those pure functions return an unneeded string, the call can be discarded.

BTW, it still is faster than splitLines simply because the line string is not stored. The GC can collect it and reuse the memory. Not so for splitLines, which must hold it all, meaning it'll be using memory that is not in the cache.

Reply via email to