Re: Mail::Box significant reducation in memory usage

Andy Maas <[email protected]> Tue, 21 Sep 2004 14:29:24 -0700
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <[email protected]>
Mark Overmeer wrote:

>* Andy Maas ([email protected]) [040921 20:28]:
>  
>
>>1. For getlines compatibility (non FastScalar getlines doesn't work in 
>>scalar context). Replace this line
>>
>>    {   # File without separators.
>>        $lines = $file->getlines;
>>
>>   with
>>
>>        {   # File without separators.
>>            eval {
>>                $lines = $file->getlines;
>>            };
>>            if ($@) {
>>                if ($@ =~ /scalar context/) {
>>                    $lines = [$file->getlines];
>>                }
>>                else {
>>                    die $@;
>>                }
>>            }
>>        }
>>    
>>
>
>Why?  $lines = [ $file->getlines ]  is slower than $lines = $file->getlines?
>  
>
I observed that calling getlines in array context cause the returned 
array to be copied (when getlines return to the caller).
So first try return by reference (avoid copying) and if fail (when using 
non FastScalar module) then fallback to the array context call.