pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files - Added PkgLint::Util::min and ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/06fb68566142
branches:  trunk
changeset: 507182:06fb68566142
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Jan 28 11:18:17 2006 +0000

description:
- 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:

 pkgtools/pkglint/files/pkglint.pl |  75 ++++++++++++++++++++++----------------
 1 files changed, 44 insertions(+), 31 deletions(-)

diffs (111 lines):

diff -r 6fe26a5a4f80 -r 06fb68566142 pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Sat Jan 28 11:11:49 2006 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Sat Jan 28 11:18:17 2006 +0000
@@ -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 @@
        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 @@
 BEGIN {
        import PkgLint::Util qw(
                false true
+               min max
        );
 }
 
@@ -596,37 +613,33 @@
                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]);
                }
        }



Home | Main Index | Thread Index | Old Index