Changeset 21904 for src/perl6

Show
Ignore:
Timestamp:
08/16/08 06:31:54 (3 months ago)
Author:
lwall
Message:

[STD] speed up parser by 33% by using P5 regex instead of TRE for ltm backoff matches

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r21901 r21904  
    520520            for my $pat (@pats) { 
    521521                $pat =~ s/\.\?$//;      # ltm backoff doesn't need tre workaround 
     522                $pat =~ s/\\>/\\b/g;    # perl regex doesn't use \> 
    522523            } 
    523524 
     
    530531                return unless $lexer; 
    531532 
    532                 pos($$buf) = $C->{_pos}; 
     533                my $P = $C->{_pos}; 
     534                pos($$buf) = $P; 
    533535 
    534536                if ($DEBUG & DEBUG::lexer) { 
     
    539541                } 
    540542 
    541                 ########################################## 
    542                 # No normal p5 match/subst below here!!! # 
    543                 ########################################## 
    544543                { 
    545                     use re::engine::TRE; 
    546  
    547544                    # if trystate is defined, the "obvious" LTM failed, so must back off 
    548545                    # a parallel nfa matcher might or might not do better here... 
     
    572569                                if ($l == -1) { 
    573570                                    my $p = '^' . $pats[$px]; 
     571                                    pos($$buf) = $P; 
    574572                                    if (($$buf =~ m/$p/xgc)) { 
    575                                         $$rxlens[$px] = $l = $+[0] - $-[0]; 
     573                                        $$rxlens[$px] = $l = pos($$buf) - $P; 
    576574                                        if ($l == $$trylen) { 
    577575                                            push @result, $fates->[$px]; 
     
    592590                                    else { 
    593591                                        my $p = '^' . $pats[$px]; 
     592                                        pos($$buf) = $P; 
    594593                                        if ($$buf =~ m/$p/xgc) { 
    595594                                            push @result, $fates->[$px]; 
     
    604603                        return @result; 
    605604                    } 
     605 
     606                    ########################################## 
     607                    # No normal p5 match/subst below here!!! # 
     608                    ########################################## 
     609                    use re::engine::TRE; 
     610 
    606611 
    607612                    $self->deb("/ running tre match at @{[ pos($$buf) ]} /") if $DEBUG & DEBUG::lexer; 
     
    14411446    pos($$buf) = $P; 
    14421447    if ($$buf =~ /$qr/gc) { 
    1443         my $len = $+[0] - $P; 
     1448        my $len = pos($$buf) - $P; 
    14441449        $self->deb("PATTERN $qr matched @{[substr($$buf,$P,$len)]} at $P $len") if $DEBUG & DEBUG::matchers; 
    14451450        my $r = $self->cursor($P+$len);