[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][lintian/lintian][master] Make File::Contents::LineLength::visit_patched_files a bit faster.



Title: GitLab

Louis-Philippe Véronneau pushed to branch master at lintian / lintian

Commits:

  • b4ca5070
    by Timo Paulssen at 2024-11-02T19:14:40+00:00
    Make File::Contents::LineLength::visit_patched_files a bit faster.
    
    No need to decode utf8 for lines shorter than our current longest
    (since the utf8 for a bit of text is always more bytes than it has
    codepoints)
    
    No need to check sql insert/update statements on every line, only
    the longest ones. And only need to check if we're in an sql file
    a single time up front.
    

1 changed file:

Changes:

  • lib/Lintian/Check/Files/Contents/LineLength.pm
    ... ... @@ -100,18 +100,23 @@ sub visit_patched_files {
    100 100
         my $longest;
    
    101 101
         my $length = $ITEM_NOT_FOUND;
    
    102 102
         my $position = 0;
    
    103
    +    my $is_sql = $item->basename =~ /sql/i;
    
    103 104
         while (my $line = <$fd>) {
    
    104 105
             $position++;
    
    105 106
     
    
    106
    -        # Skip SQL insert and select statements
    
    107
    -        next if ($line =~ /^(INSERT|SELECT)\s/i
    
    108
    -            and $item->basename =~ /sql/i);
    
    107
    +        # If the line can't be longer than our current longest,
    
    108
    +        # no need to decode.
    
    109
    +        next if( length $line < $length );
    
    109 110
     
    
    110 111
             # count codepoints, if possible
    
    111 112
             $line = decode_utf8($line)
    
    112 113
               if valid_utf8($line);
    
    113 114
     
    
    114 115
             if( length $line > $length ) {
    
    116
    +            # Skip SQL insert and select statements
    
    117
    +            next if ($is_sql
    
    118
    +                and $line =~ /^(INSERT|SELECT)\s/i);
    
    119
    +
    
    115 120
                 $longest = $position;
    
    116 121
                 $length = length $line;
    
    117 122
             }
    


  • Reply to: