Re: Mail::Box significant reducation in memory usage
Mark Overmeer <[email protected]> Wed, 22 Sep 2004 10:17:39 +0200
| Newsgroups | gmane.comp.lang.perl.modules.mail-box |
|---|---|
| Organization | MARKOV Solutions |
| Message-ID | <[email protected]> |
* Andy Maas ([email protected]) [040921 23:29]: > Mark Overmeer wrote: > > >* Andy Maas ([email protected]) [040921 20:28]: > >> { # 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. I do not like this trick at all. It's easier to say: if(ref $file eq 'Mail::Box::FastScalar') { $lines = $file->getlines; } else { $lines = [$file->getlines]; } By the way: I have modified Mail::Box::Parser::C in XS to return a ref array. That parser is a lot faster than the perl based parser... Thanks for your contribution. -- MarkOv ------------------------------------------------------------------------ drs Mark A.C.J. Overmeer MARKOV Solutions [email protected] [email protected] http://Mark.Overmeer.net http://solutions.overmeer.net