r49272 - in /trunk/libtext-findindent-perl: Changes META.yml debian/changelog lib/Text/FindIndent.pm

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Wed Dec 23 16:51:48 UTC 2009


Author: jawnsy-guest
Date: Wed Dec 23 16:51:41 2009
New Revision: 49272

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=49272
Log:
New upstream release

Modified:
    trunk/libtext-findindent-perl/Changes
    trunk/libtext-findindent-perl/META.yml
    trunk/libtext-findindent-perl/debian/changelog
    trunk/libtext-findindent-perl/lib/Text/FindIndent.pm

Modified: trunk/libtext-findindent-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-findindent-perl/Changes?rev=49272&op=diff
==============================================================================
--- trunk/libtext-findindent-perl/Changes (original)
+++ trunk/libtext-findindent-perl/Changes Wed Dec 23 16:51:41 2009
@@ -1,4 +1,10 @@
 Changes for Perl extension Text-FindIndent
+
+0.07
+	- ~40% faster since 0.05
+
+0.06 
+	- ~20-25% faster
 
 0.05 
 	- "skip_pod" option to parse() for skipping POD sections.

Modified: trunk/libtext-findindent-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-findindent-perl/META.yml?rev=49272&op=diff
==============================================================================
--- trunk/libtext-findindent-perl/META.yml (original)
+++ trunk/libtext-findindent-perl/META.yml Wed Dec 23 16:51:41 2009
@@ -23,4 +23,4 @@
   perl: 5.00503
 resources:
   license: http://dev.perl.org/licenses/
-version: 0.05
+version: 0.07

Modified: trunk/libtext-findindent-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-findindent-perl/debian/changelog?rev=49272&op=diff
==============================================================================
--- trunk/libtext-findindent-perl/debian/changelog (original)
+++ trunk/libtext-findindent-perl/debian/changelog Wed Dec 23 16:51:41 2009
@@ -1,3 +1,9 @@
+libtext-findindent-perl (0.07-1) UNRELEASED; urgency=low
+
+  * New upstream release
+
+ -- Jonathan Yu <jawnsy at cpan.org>  Wed, 23 Dec 2009 08:33:04 -0500
+
 libtext-findindent-perl (0.05-1) unstable; urgency=low
 
   [ Jonathan Yu ]

Modified: trunk/libtext-findindent-perl/lib/Text/FindIndent.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-findindent-perl/lib/Text/FindIndent.pm?rev=49272&op=diff
==============================================================================
--- trunk/libtext-findindent-perl/lib/Text/FindIndent.pm (original)
+++ trunk/libtext-findindent-perl/lib/Text/FindIndent.pm Wed Dec 23 16:51:41 2009
@@ -73,8 +73,10 @@
 
 use vars qw{$VERSION};
 BEGIN {
-  $VERSION = '0.05';
+  $VERSION = '0.07';
 }
+
+use constant MAX_LINES => 500;
 
 sub parse {
   my $class = shift;
@@ -92,6 +94,23 @@
   my $prev_indent           = undef;
   my $skip                  = 0;
   my $in_pod                = 0;
+
+  # Do we have emacs smart comments?
+  $class->_check_emacs_local_variables_at_file_end($textref, \%modeline_settings);
+  if (exists $modeline_settings{softtabstop} and exists $modeline_settings{usetabs}) {
+    $modeline_settings{mixedmode} = $modeline_settings{usetabs}
+      if not defined $modeline_settings{mixedmode};
+    return(
+      ($modeline_settings{mixedmode} ? "m" : "s")
+      . $modeline_settings{softtabstop}
+    );
+  }
+  elsif (exists $modeline_settings{tabstop} and $modeline_settings{usetabs}) {
+    return( ($modeline_settings{mixedmode} ? "m" : "t") . $modeline_settings{tabstop} );
+  }
+  elsif (exists $modeline_settings{tabstop} and exists $modeline_settings{usetabs}) {
+    return( "s" . $modeline_settings{tabstop} );
+  }
 
   while ($$textref =~ /\G([ \t]*)([^\r\n]*)[\r\n]+/cgs) {
     my $ws       = $1;
@@ -100,31 +119,36 @@
     $lines++;
     
     # check emacs start line stuff with some slack (shebang)
+    my $changed_modelines;
     if ($lines < 3) {
-      $class->_check_emacs_local_variables_first_line($fullline, \%modeline_settings);
-    }
+      $changed_modelines = $class->_check_emacs_local_variables_first_line($fullline, \%modeline_settings);
+    }
+
+    # Do we have emacs smart comments?
+    # ==> Done once at start
+    #$class->_check_emacs_local_variables($fullline, \%modeline_settings);
 
     # Do we have vim smart comments?
-    $class->_check_vim_modeline($fullline, \%modeline_settings);
-
-    # Do we have emacs smart comments?
-    $class->_check_emacs_local_variables($fullline, \%modeline_settings);
-
-    if (exists $modeline_settings{softtabstop} and exists $modeline_settings{usetabs}) {
-      $modeline_settings{mixedmode} = $modeline_settings{usetabs}
-        if not defined $modeline_settings{mixedmode};
-      return(
-        ($modeline_settings{mixedmode} ? "m" : "s")
-        . $modeline_settings{softtabstop}
-      );
-    }
-    elsif (exists $modeline_settings{tabstop} and $modeline_settings{usetabs}) {
-      return( ($modeline_settings{mixedmode} ? "m" : "t") . $modeline_settings{tabstop} );
-    }
-    elsif (exists $modeline_settings{tabstop} and exists $modeline_settings{usetabs}) {
-      return( "s" . $modeline_settings{tabstop} );
-    }
-
+    if ($class->_check_vim_modeline($fullline, \%modeline_settings) || $changed_modelines) {
+      if (exists $modeline_settings{softtabstop} and exists $modeline_settings{usetabs}) {
+        $modeline_settings{mixedmode} = $modeline_settings{usetabs}
+          if not defined $modeline_settings{mixedmode};
+        return(
+          ($modeline_settings{mixedmode} ? "m" : "s")
+          . $modeline_settings{softtabstop}
+        );
+      }
+      elsif (exists $modeline_settings{tabstop} and $modeline_settings{usetabs}) {
+        return( ($modeline_settings{mixedmode} ? "m" : "t") . $modeline_settings{tabstop} );
+      }
+      elsif (exists $modeline_settings{tabstop} and exists $modeline_settings{usetabs}) {
+        return( "s" . $modeline_settings{tabstop} );
+      }
+    }
+
+    if ($lines > MAX_LINES) {
+      next;
+    }
 
     if ($skip) {
       $skip--;
@@ -140,9 +164,7 @@
       }
 
     }
-    next if $in_pod;
-
-    next if $rest eq '';
+    next if $in_pod or $rest eq '';
 
     if ($ws eq '') {
       $prev_indent = $ws;
@@ -171,7 +193,6 @@
       $prev_indent = $ws;
       next;
     }
-
 
     # at this point, we're desperate!
     my $prev_spaces = $prev_indent;
@@ -253,10 +274,45 @@
   }
 }
 
-sub _check_vim_modeline {
-  my $class = shift;
-  my $line = shift;
-  my $settings = shift;
+{
+  # the vim modeline regexes
+  my $VimTag = qr/(?:ex|vi(?:m(?:[<=>]\d+)?)?):/;
+  my $OptionArg = qr/[^\s\\]*(?:\\[\s\\][^\s\\]*)*/;
+  my $VimOption = qr/
+    \w+(?:=)?$OptionArg
+  /xo;
+
+  my $VimModeLineStart = qr/(?:^|\s+)$VimTag/o;
+
+  # while technically, we match against $VimModeLineStart before,
+  # IF there is a vim modeline, we don't need to optimize
+  my $VimModelineTypeOne = qr/
+    $VimModeLineStart
+    \s*
+    ($VimOption
+      (?:
+        (?:\s*:\s*|\s+)
+        $VimOption
+      )*
+    )
+    \s*$
+  /xo;
+  
+  my $VimModelineTypeTwo = qr/
+    $VimModeLineStart
+    \s*
+    set?\s+
+    ($VimOption
+      (?:\s+$VimOption)*
+    )
+    \s*
+    :
+  /xo;
+
+  sub _check_vim_modeline {
+    my $class = shift;
+    my $line = shift;
+    my $settings = shift;
 
 # Quoting the vim docs:
 # There are two forms of modelines.  The first form:
@@ -289,59 +345,34 @@
 #Example:
 #   /* vim: set ai tw=75: */ ~
 #
- 
-  my $vimtag = qr/(?:vi(?:m(?:[<=>]\d+)?)?|ex):/;
-  my $option_arg = qr/[^\s\\]*(?:\\[\s\\][^\s\\]*)*/;
-  my $option = qr/
-    \w+(?:=)?$option_arg
-  /x;
-  my $modeline_type_one = qr/
-    \s+
-    $vimtag
-    \s*
-    ($option
-      (?:
-        (?:\s*:\s*|\s+)
-        $option
-      )*
-    )
-    \s*$
-  /x;
-  
-  my $modeline_type_two = qr/
-    \s+
-    $vimtag
-    \s*
-    set?\s+
-    ($option
-      (?:\s+$option)*
-    )
-    \s*
-    :
-  /x;
-
-
-  my @options;
-  if ($line =~ $modeline_type_one) {
-    push @options, split /(?!<\\)[:\s]+/, $1;
-  }
-  elsif ($line =~ $modeline_type_two) {
-    push @options, split /(?!<\\)\s+/, $1;
-  }
-  else {
-    return;
-  }
-
-  return if not @options;
-
-  foreach (@options) {
-    /s(?:ts|ofttabstop)=(\d+)/i and $settings->{softtabstop} = $1, next;
-    /t(?:s|abstop)=(\d+)/i and $settings->{tabstop} = $1, next;
-    /((?:no)?)(?:expandtab|et)/i and $settings->{usetabs} = (defined $1 and $1 =~ /no/i ? 1 : 0), next;
-  }
-  return;
+   
+    my $changed = 0;
+    my @options;
+    if ($line =~ $VimModeLineStart) {
+      if ($line =~ $VimModelineTypeOne) {
+        push @options, split /(?!<\\)[:\s]+/, $1;
+      }
+      elsif ($line =~ $VimModelineTypeTwo) {
+        push @options, split /(?!<\\)\s+/, $1;
+      }
+      else {
+        return;
+      }
+    }
+    else {
+      return;
+    }
+
+    return if not @options;
+
+    foreach (@options) {
+      /s(?:ts|ofttabstop)=(\d+)/i and $settings->{softtabstop} = $1, $changed = 1, next;
+      /t(?:s|abstop)=(\d+)/i and $settings->{tabstop} = $1, $changed = 1,  next;
+      /((?:no)?)(?:expandtab|et)/i and $settings->{usetabs} = (defined $1 and $1 =~ /no/i ? 1 : 0), $changed = 1, next;
+    }
+    return $changed;
+  }
 }
-
 
 
 
@@ -396,6 +427,10 @@
   $stylelookup{'whitesmith'} = $stylelookup{kr};
   $stylelookup{'stroustrup'} = $stylelookup{kr};
 
+  my $FirstLineVar = qr/[^\s:]+/;
+  my $FirstLineValue = qr/[^;]+/; # dumb
+  my $FirstLinePair = qr/\s*$FirstLineVar\s*:\s*$FirstLineValue;/o;
+  my $FirstLineRegexp = qr/-\*-\s*mode:\s*[^\s;]+;\s*($FirstLinePair+)\s*-\*-/o;
   
   
   sub _check_emacs_local_variables_first_line {
@@ -410,25 +445,24 @@
 # ;; -*- mode: Lisp; fill-column: 75; comment-column: 50; -*-
 
 
-    my $var = qr/[^\s:]+/;
-    my $value = qr/[^;]+/; # dumb
-    my $pair = qr/\s*$var\s*:\s*$value;/;
-    my $firstline = qr/-\*-\s*mode:\s*[^\s;]+;\s*($pair+)\s*-\*-/;
-    if ($line =~ $firstline) {
+    my $changed = 0;
+    if ($line =~ $FirstLineRegexp) {
       my @pairs = split /\s*;\s*/, $1;
       foreach my $pair (@pairs) {
         my ($key, $value) = split /\s*:\s*/, $pair, 2;
         if ($key eq 'tab-width') {
           $settings->{tabstop} = $value;# FIXME: check var
+          $changed = 1;
         }
         elsif ($key eq 'indent-tabs-mode') {
-          $tabmodelookup{$value}->($settings) if defined $tabmodelookup{$value};
+          $tabmodelookup{$value}->($settings), $changed = 1 if defined $tabmodelookup{$value};
         }
         elsif ($key eq 'c-basic-offset') {
           $settings->{tabstop} ||= $value; # tab-width takes precedence!?
+          $changed = 1;
         }
         elsif ($key eq 'style') { # this is quite questionable practice...
-          $stylelookup{$value}->($settings) if defined $stylelookup{$value};
+          $stylelookup{$value}->($settings), $changed = 1 if defined $stylelookup{$value};
         }
       }
     }
@@ -438,7 +472,7 @@
     #$settings->{softtabstop} = $settings->{style_softtabstop} if not exists $settings->{softtabstop};
     #$settings->{usetabs}     = $settings->{style_usetabs}     if not exists $settings->{usetabs};
 
-    return();
+    return $changed;
   }
 
   sub _check_emacs_local_variables {
@@ -515,6 +549,20 @@
     }
   }
 
+  sub _check_emacs_local_variables_at_file_end {
+    my $class = shift;
+    my $textref = shift;
+    my $settings = shift;
+    my $len = length($$textref);
+    my $start = $len-3000;
+    $start = 0 if $start < 0;
+    my $text = substr($$textref, $start);
+
+    while ($text =~ /\G[ \t]*([^\r\n]*)[\r\n]+/cgs) {
+      $class->_check_emacs_local_variables($1, $settings);
+    }
+    return;
+  }
 } # end lexical block for emacs lookups
 
 




More information about the Pkg-perl-cvs-commits mailing list