diff options
author | rillig <rillig@pkgsrc.org> | 2006-01-28 11:18:17 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2006-01-28 11:18:17 +0000 |
commit | 20511917c537411dce366ee758424c68b6b4d84b (patch) | |
tree | 85baa205690a510f45b248e5802baf5c43e02ca8 /pkgtools | |
parent | 6af5ebf4c70ecad4a75cdce61b210b30bfb405e2 (diff) | |
download | pkgsrc-20511917c537411dce366ee758424c68b6b4d84b.tar.gz |
- Added PkgLint::Util::min and PkgLint::Util::max.
- Rewrote PkgLint::String::substring to make it look less like a Brainf***
program. I guess this will greatly improve execution speed.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkglint/files/pkglint.pl | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl index 714de101fe7..5e5f50db84d 100644 --- a/pkgtools/pkglint/files/pkglint.pl +++ b/pkgtools/pkglint/files/pkglint.pl @@ -1,5 +1,5 @@ #! @PERL@ -# $NetBSD: pkglint.pl,v 1.492 2006/01/28 11:11:49 rillig Exp $ +# $NetBSD: pkglint.pl,v 1.493 2006/01/28 11:18:17 rillig Exp $ # # pkglint - static analyzer and checker for pkgsrc packages @@ -43,12 +43,28 @@ BEGIN { use Exporter; use vars qw(@ISA @EXPORT_OK); @ISA = qw(Exporter); - @EXPORT_OK = qw(array_to_hash false print_table true); + @EXPORT_OK = qw( + false true + min max + array_to_hash print_table + ); } use constant false => 0; use constant true => 1; +sub min($$) { + my ($a, $b) = @_; + + return ($a < $b) ? $a : $b; +} + +sub max($$) { + my ($a, $b) = @_; + + return ($a > $b) ? $a : $b; +} + # Prints the C<$table> on the C<$out> stream. The C<$table> shall be an # array of rows, each row shall be an array of cells, and each cell shall # be a string. @@ -539,6 +555,7 @@ package PkgLint::String; BEGIN { import PkgLint::Util qw( false true + min max ); } @@ -596,37 +613,33 @@ sub substring($$$) { if (ref($part) eq "") { my $p = ""; - while ($skip > 0 && $part ne "") { - $skip--; - $part = substr($part, 1); - } - while ($take > 0 && $part ne "") { - $take--; - $p .= substr($part, 0, 1); - $part = substr($part, 1); - } + my $nskipped = min($skip, strlen($part)); + $skip -= $nskipped; + $part = substr($part, $nskipped); + + my $ntaken = min($take, strlen($part)); + $take -= $ntaken; + $p .= substr($part, 0, $ntaken); + $part = substr($part, $ntaken); + push(@nparts, $p); } else { - my ($toline, $tocol, $tolen, $line, $linelen, $col); - my ($start, $end); - - $line = $part->[P_LINENO]; - $col = $part->[P_STARTCOL]; - $tocol = $part->[P_ENDCOL]; - - $linelen = length($physlines->[$line]->[1]); - while ($skip > 0 && $col < $tocol) { - last if ($col == $linelen); - $skip--; - $col++; - } - $start = $col; - while ($take > 0 && $col < $tocol) { - last if ($col == $linelen); - $take--; - $col++; - } - $end = $col; + my $line = $part->[P_LINENO]; + my $col = $part->[P_STARTCOL]; + my $tocol = $part->[P_ENDCOL]; + my $linelen = length($physlines->[$line]->[1]); + + my $nskipped = max(0, min($skip, min($tocol - $col, $linelen - $col))); + $skip -= $nskipped; + $col += $nskipped; + + my $start = $col; + + my $ntaken = max(0, min($take, min($tocol - $col, $linelen - $col))); + $take -= $ntaken; + $col += $ntaken; + + my $end = $col; push(@nparts, [$line, $start, $end]); } } |