warnings::import() can exit quickly and efficiently if @_ is empty.
authorNicholas Clark <nick@ccl4.org>
Sat, 19 Jun 2010 20:55:41 +0000 (21:55 +0100)
committerNicholas Clark <nick@ccl4.org>
Wed, 23 Jun 2010 07:44:42 +0000 (08:44 +0100)
For this platform, cachegrind reckons warnings->import() uses 7% fewer
instructions executed and has 9% fewer L1 cache references.

lib/warnings.pm
warnings.pl

index 10a7cbf..c6881fe 100644 (file)
@@ -6,7 +6,7 @@
 
 package warnings;
 
-our $VERSION = '1.09';
+our $VERSION = '1.10';
 
 # Verify that we're called correctly so that warnings will work.
 # see also strict.pm.
@@ -368,10 +368,6 @@ sub import
 {
     shift;
 
-    my $catmask ;
-    my $fatal = 0 ;
-    my $no_fatal = 0 ;
-
     my $mask = ${^WARNING_BITS} ;
 
     if (vec($mask, $Offsets{'all'}, 1)) {
@@ -379,7 +375,14 @@ sub import
         $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
     }
     
-    push @_, 'all' unless @_;
+    unless (@_) {
+       # This is equivalent to @_ = 'all' ;
+       return ${^WARNING_BITS} = $mask | $Bits{all} ;
+    }
+
+    my $catmask ;
+    my $fatal = 0 ;
+    my $no_fatal = 0 ;
 
     foreach my $word ( @_ ) {
        if ($word eq 'FATAL') {
index 59d8652..87bf96a 100644 (file)
@@ -452,7 +452,7 @@ __END__
 
 package warnings;
 
-our $VERSION = '1.09';
+our $VERSION = '1.10';
 
 # Verify that we're called correctly so that warnings will work.
 # see also strict.pm.
@@ -653,10 +653,6 @@ sub import
 {
     shift;
 
-    my $catmask ;
-    my $fatal = 0 ;
-    my $no_fatal = 0 ;
-
     my $mask = ${^WARNING_BITS} ;
 
     if (vec($mask, $Offsets{'all'}, 1)) {
@@ -664,7 +660,14 @@ sub import
         $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
     }
     
-    push @_, 'all' unless @_;
+    unless (@_) {
+       # This is equivalent to @_ = 'all' ;
+       return ${^WARNING_BITS} = $mask | $Bits{all} ;
+    }
+
+    my $catmask ;
+    my $fatal = 0 ;
+    my $no_fatal = 0 ;
 
     foreach my $word ( @_ ) {
        if ($word eq 'FATAL') {