Show
Ignore:
Timestamp:
04/02/09 06:05:25 (4 years ago)
Author:
dankogai
Message:

more optimization

Location:
lang/perl/Text-Darts/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Text-Darts/trunk/Changes

    r31702 r31804  
    44# 
    55$Revision: 0.6 $ $Date: 2009/03/30 12:57:33 $ 
     6! Darts.xs lib/Text/Darts.pm 
     7  More optimization 
     8 
     90.06 2009/03/30 12:57:33 
    610! Darts.xs lib/Text/Darts.pm 
    711  Optimized gsub($str, \%hashref); 
  • lang/perl/Text-Darts/trunk/Darts.xs

    r31702 r31804  
    7070} 
    7171 
     72 
    7273static SV *da_gsub(int dpi, SV *src, SV *rep){ 
    73     SV *result = newSV(0); 
     74    SV *result = newSV(SvCUR(src) * 2); 
    7475    Darts::DoubleArray *dp = INT2PTR(Darts::DoubleArray *, dpi); 
    7576    Darts::DoubleArray::result_pair_type  result_pair[MAX_NMATCH]; 
     
    7980 
    8081    while (head < tail) { 
    81         size_t size =  
    82             dp->commonPrefixSearch(head,result_pair, sizeof(result_pair)); 
    83         size_t seekto = 0;        
     82        char *ohead = head; 
     83        size_t size, slen; 
     84        while(head < tail){ 
     85            size =  
     86                dp->commonPrefixSearch(head,result_pair, sizeof(result_pair)); 
     87            if (size) break; 
     88            head++; 
     89        } 
     90        if (head != ohead){ 
     91            sv_catpvn(result, ohead, (head - ohead)); 
     92        } 
    8493        if (size) { 
     94            size_t seekto = 0;        
    8595            for (size_t i = 0; i < size; ++i) { 
    8696                if (seekto < result_pair[i].length) 
     
    94104                head += seekto; 
    95105            } 
    96         } 
    97         if (seekto == 0) { 
    98             sv_catpvn(result, head, 1); 
    99             ++head;  
    100106        } 
    101107    } 
  • lang/perl/Text-Darts/trunk/lib/Text/Darts.pm

    r31702 r31804  
    1111sub new{ 
    1212    my $pkg = shift; 
    13     my $dpi = xs_make([sort @_]); 
     13    my $dpi = xs_make([ grep { $_ } sort @_]); 
    1414    bless \$dpi, $pkg; 
    1515} 
  • lang/perl/Text-Darts/trunk/t/benchmark.pl

    r3501 r31804  
    77 
    88my $str = do { open my $fh, __FILE__; local $/; my $s = <$fh>; close $fh; $s }; 
    9 my @words = do { my %h; $h{$_}++ for split /\W+/, $str; keys %h }; 
     9my @words = do { my %h; $_ and $h{$_}++ for split /\W+/, $str; keys %h }; 
    1010 
    1111my $td = Text::Darts->new(@words); 
     
    1818      { 
    1919          Darts => sub { 
    20               $td->gsub( $str, sub { "<$_[0]>" } ); 
    21           }, 
     20              $td->gsub( $str, sub { "<$_[0]>" } ); 
     21          }, 
    2222          'R::A' => sub { 
    2323              my $tmp = $str;