Changeset 11125


Ignore:
Timestamp:
03/15/10 10:40:29 (2 years ago)
Author:
zenogantner
Message:

speed up counting of non-whitespace characters by roughly a factor of 5 for typical documents
removed stats for selected text (was not reflected by the GUI anyway)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Document.pm

    r11008 r11125  
    13051305 
    13061306    my $editor = $self->editor; 
    1307     my $src    = $editor->GetSelectedText; 
    1308     my $code; 
    1309     if ($src) { 
    1310         $code = $src; 
    1311  
    1312         my $code2 = $code; # it's ugly, need improvement 
    1313         $code2 =~ s/\r\n/\n/g; 
    1314         $lines = 1;        # by default 
    1315         $lines++ while ( $code2 =~ /[\r\n]/g ); 
    1316         $chars_with_space = length($code); 
    1317     } else { 
    1318         $code = $self->text_get; 
    1319  
    1320         # I trust editor more 
    1321         $lines            = $editor->GetLineCount(); 
    1322         $chars_with_space = $editor->GetTextLength(); 
    1323         $is_readonly      = $editor->GetReadOnly(); 
    1324     } 
     1307    my $code = $self->text_get; 
     1308 
     1309    $lines            = $editor->GetLineCount(); 
     1310    $chars_with_space = $editor->GetTextLength(); 
     1311    $is_readonly      = $editor->GetReadOnly(); 
    13251312 
    13261313    # avoid slow calculation on large files 
    1327     # TO DO or improve them ? 
    1328     if ( length($code) < 100_000 ) { 
     1314    # TODO or improve them? 
     1315    if ( length($code) < 500_000 ) { 
     1316        my $whitespace_chars = 0; 
    13291317        $words++               while ( $code =~ /\b\w+\b/g ); 
    1330         $chars_without_space++ while ( $code =~ /\S/g ); 
     1318        $chars_without_space = $chars_with_space; 
     1319        $chars_without_space-- while ( $code =~ /\s/g ); 
    13311320    } else { 
    13321321        $words               = Wx::gettext("Skipped for large files"); 
     
    13401329    require Padre::Locale; 
    13411330    if ( not $self->{encoding} or $self->{encoding} eq 'ascii' ) { 
    1342         $self->{encoding} = Padre::Locale::encoding_from_string($src); 
     1331        $self->{encoding} = Padre::Locale::encoding_from_string($code); 
    13431332    } 
    13441333    return ( 
Note: See TracChangeset for help on using the changeset viewer.