Changeset 20390


Ignore:
Timestamp:
2009-08-25T14:43:41+12:00 (15 years ago)
Author:
mdewsnip
Message:

Improved cfgread::read_cfg_line() so it doesn't take forever to parse collect.cfg files containing large multi-line values (e.g. format statements, collectionextra values etc.). It was very slow previously because it was doing a fairly complex regular expression on the full value each time it read a line for the multi-line value. Since the value was getting longer and longer with each line read, the regular expression was taking longer and longer.

By Michael Dewsnip, DL Consulting Ltd.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/cfgread.pm

    r18441 r20390  
    4444    if ($line =~ m/^([\"\'])/ || $line =~ m/[^\\]([\"\'])/) {
    4545        my $quote=$1;
    46         while ($line !~ m/$quote(.*?[^\\])?(\\\\)*$quote/) {
    47         my $nextline = <$handle>;
    48         if (defined($nextline)) {
     46
     47        # Improve speed substantially by not doing the regular expression on $line in the while loop
     48        #   (since $line gets longer each iteration, the regular expression gets slower and slower)
     49        # Instead we just check each new line to see if it finishes the quoted multi-line value
     50        if ($line !~ m/$quote(.*?[^\\])?(\\\\)*$quote/)
     51        {
     52        my $nextline;
     53        while (defined($nextline = <$handle>))
     54        {
    4955            $nextline =~ s/\r?\n//; # remove end-of-line
    5056            $line .= " " . $nextline;
    51         } else {
    52             return undef; # parse error?
     57
     58            # Break out of the while loop if we've found the end of the multi-line value
     59            last if ($nextline =~ m/^(.*?[^\\])?(\\\\)*$quote/);
    5360        }
    5461        }
Note: See TracChangeset for help on using the changeset viewer.