In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/8f8c2a4448d4895f07a65262094032f124603527?hp=f0a8fd683c572d39673f9b0a22fd4919c1bed5a7>
- Log ----------------------------------------------------------------- commit 8f8c2a4448d4895f07a65262094032f124603527 Author: Nicholas Clark <[email protected]> Date: Tue Jun 22 09:59:49 2010 +0100 Tweak the generated Errno.pm slightly. Shorter and slightly fewer ops. Use our directly at the first assignment, rather than on a line by itself. Add editor readonly blocks, consistent with most other generated files. require Exporter, rather than using it with an empty import list. We don't need it at compile time. M ext/Errno/Errno_pm.PL commit 96183d25c8bf116d31888a79fd63a86056518da1 Author: Nicholas Clark <[email protected]> Date: Sun Jun 20 18:00:31 2010 +0100 Move parameter validation, and carp/croak generation into warnings::__chk. This results in enabled, fatal_enabled, warnif, and warn as wrappers to __chk selecting their desired behaviour, and eliminates duplicated code. M lib/warnings.pm M warnings.pl commit 8787a7475e25239a0fffec22fe068e97240c2a51 Author: Nicholas Clark <[email protected]> Date: Sun Jun 20 16:23:38 2010 +0100 Move the repeated vec logic into warnings::__chk. M lib/warnings.pm M warnings.pl commit 980a43b097489a68f8b49125b2258eb2697e313e Author: Nicholas Clark <[email protected]> Date: Sun Jun 20 14:40:33 2010 +0100 No need to return $i from warnings::__chk, as the value is not used. $i holds the depth of the caller frame from which the warnings bitmask is read. The value has not been used by any caller of __chk() since c3186b657097c822. M lib/warnings.pm M warnings.pl commit 4e92cb89227aa006b421b88be064b91da43489dc Author: Nicholas Clark <[email protected]> Date: Sun Jun 20 14:12:38 2010 +0100 Make warnings::__chk default the returned caller's bitmask to 0. This removes defined checks in subsequence code paths, reducing complexity. M lib/warnings.pm M warnings.pl commit a5094cb03518019abe3dfffccbe657c8edc0e0c2 Author: Nicholas Clark <[email protected]> Date: Sun Jun 20 11:37:40 2010 +0100 In Config::import, avoid assigning to $pkg, which is never read. Avoid the use of sprintf - __PACKAGE__ is a constant, so can be inlined within the message string. Don't store '%Config' in %Export_Cache, as that's only used to deal with exported functions. The variable %Config is special-cased. On this platform, cachegrind shows a 1% reduction in instruction count and L1 cache references as a result. M configpm commit f897bda4768f481fed99f4d632f63dbecb999c01 Author: Nicholas Clark <[email protected]> Date: Sat Jun 19 22:43:41 2010 +0100 In vars::import, avoid assigning to $pack, which is never read. On this platform, cachegrind shows a 0.5% reduction in instruction count and L1 cache references as a result. A tiny gain for every instance of use vars ...; M lib/vars.pm commit 4c02ac936e9cd63efc582d138cd258830b6e2e0c Author: Nicholas Clark <[email protected]> Date: Sat Jun 19 22:32:33 2010 +0100 Merge the guts of warnings::import and warnings::bits into _bits. Additionally, removing the scope entry caused by the {} in the fast path of &import reduces instruction count and L1 cache misses for warnings->import() by 3%. M lib/warnings.pm M warnings.pl commit 8452af9f2d8674af680c1e3be7554590d5d7261c Author: Nicholas Clark <[email protected]> Date: Sat Jun 19 21:55:41 2010 +0100 warnings::import() can exit quickly and efficiently if @_ is empty. For this platform, cachegrind reckons warnings->import() uses 7% fewer instructions executed and has 9% fewer L1 cache references. M lib/warnings.pm M warnings.pl commit b46acf92a1bd83c189c4290dd3ae7f5bfa32d2a7 Author: Nicholas Clark <[email protected]> Date: Sat Jun 19 21:27:45 2010 +0100 Convert Config::fetch_string to use a regexp, rather than index and substr. For this platform, cachegrind reckons a 0.5% reduction in L1 cache refs and 0.5% reduction in instructions executed, which whilst small, is a step in the right direction. M configpm ----------------------------------------------------------------------- Summary of changes: configpm | 69 +++++++++---------------- ext/Errno/Errno_pm.PL | 15 +++--- lib/vars.pm | 4 +- lib/warnings.pm | 135 +++++++++++++++++++++---------------------------- warnings.pl | 135 +++++++++++++++++++++---------------------------- 5 files changed, 148 insertions(+), 210 deletions(-) diff --git a/configpm b/configpm index b8fea15..87feab5 100755 --- a/configpm +++ b/configpm @@ -188,13 +188,16 @@ sub config_sh; sub config_vars; sub config_re; -my %%Export_Cache = map {($_ => 1)} (@Config::EXPORT, @Config::EXPORT_OK); +# Skip @Config::EXPORT because it only contains %%Config, which we special +# case below as it's not a function. @Config::EXPORT won't change in the +# lifetime of Perl 5. +my %%Export_Cache = map {($_ => 1)} @Config::EXPORT_OK; our %%Config; # Define our own import method to avoid pulling in the full Exporter: sub import { - my $pkg = shift; + shift; @_ = @Config::EXPORT unless @_; my @funcs = grep $_ ne '%%Config', @_; @@ -203,8 +206,8 @@ sub import { no strict 'refs'; my $callpkg = caller(0); foreach my $func (@funcs) { - die sprintf qq{"%%s" is not exported by the %%s module\n}, - $func, __PACKAGE__ unless $Export_Cache{$func}; + die qq{"$func" is not exported by the Config module\n} + unless $Export_Cache{$func}; *{$callpkg.'::'.$func} = \&{$func}; } @@ -291,63 +294,41 @@ EOT if ($seen_quotes{'"'}) { # We need the full ' and " code - $fetch_string .= <<'EOT'; - my $quote_type = "'"; - my $marker = "$key="; - - # Check for the common case, ' delimited - my $start = index($Config_SH_expanded, "\n$marker$quote_type"); - # If that failed, check for " delimited - if ($start == -1) { - $quote_type = '"'; - $start = index($Config_SH_expanded, "\n$marker$quote_type"); - } -EOT -} else { - $fetch_string .= <<'EOT'; - # We only have ' delimted. - my $start = index($Config_SH_expanded, "\n$key=\'"); -EOT -} -$fetch_string .= <<'EOT'; - # Start can never be -1 now, as we've rigged the long string we're - # searching with an initial dummy newline. - return undef if $start == -1; - - $start += length($key) + 3; -EOT -if (!$seen_quotes{'"'}) { - # Don't need the full ' and " code, or the eval expansion. - $fetch_string .= <<'EOT'; - my $value = substr($Config_SH_expanded, $start, - index($Config_SH_expanded, "'\n", $start) - - $start); -EOT -} else { - $fetch_string .= <<'EOT'; - my $value = substr($Config_SH_expanded, $start, - index($Config_SH_expanded, "$quote_type\n", $start) - - $start); +$fetch_string .= <<'EOT'; + return undef unless my ($quote_type, $value) = $Config_SH_expanded =~ /\n$key=(['"])(.*?)\1\n/s; # If we had a double-quote, we'd better eval it so escape # sequences and such can be interpolated. Since the incoming # value is supposed to follow shell rules and not perl rules, # we escape any perl variable markers + + # Historically, since " 'support' was added in change 1409, the + # interpolation was done before the undef. Stick to this arguably buggy + # behaviour as we're refactoring. if ($quote_type eq '"') { $value =~ s/\$/\\\$/g; $value =~ s/\@/\\\@/g; eval "\$value = \"$value\""; } -EOT + + # So we can say "if $Config{'foo'}". + $self->{$key} = $value eq 'undef' ? undef : $value; # cache it } +EOT + +} else { + # We only have ' delimted. + $fetch_string .= <<'EOT'; + return undef unless $Config_SH_expanded =~ /\n$key=\'(.*?)\'\n/s; # So we can say "if $Config{'foo'}". - $value = undef if $value eq 'undef'; - $self->{$key} = $value; # cache it + $self->{$key} = $1 eq 'undef' ? undef : $1; } EOT +} + eval $fetch_string; die if $@; diff --git a/ext/Errno/Errno_pm.PL b/ext/Errno/Errno_pm.PL index e0e328f..0899dde 100644 --- a/ext/Errno/Errno_pm.PL +++ b/ext/Errno/Errno_pm.PL @@ -334,13 +334,13 @@ EOF # Write Errno.pm print <<"EDQ"; +# -*- buffer-read-only: t -*- # # This file is auto-generated. ***ANY*** changes here will be lost # package Errno; -our (\...@isa,\$VERSION); -use Exporter (); +require Exporter; use Config; use strict; @@ -348,9 +348,9 @@ use strict; "$Config{'archname'}-$Config{'osvers'}" or die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})"; -\$VERSION = "$VERSION"; +our \$VERSION = "$VERSION"; \$VERSION = eval \$VERSION; -...@isa = qw(Exporter); +our \...@isa = 'Exporter'; my %err; @@ -378,11 +378,9 @@ print <<'ESQ'; } } -our (@EXPORT_OK, %EXPORT_TAGS); +our @EXPORT_OK = keys %err; -...@export_ok = keys %err; - -%EXPORT_TAGS = ( +our %EXPORT_TAGS = ( POSIX => [qw( ESQ @@ -493,6 +491,7 @@ under the same terms as Perl itself. =cut +# ex: set ro: ESQ } diff --git a/lib/vars.pm b/lib/vars.pm index a0151b8..8ec107c 100644 --- a/lib/vars.pm +++ b/lib/vars.pm @@ -2,14 +2,14 @@ package vars; use 5.006; -our $VERSION = '1.01'; +our $VERSION = '1.02'; use warnings::register; use strict qw(vars subs); sub import { my $callpack = caller; - my ($pack, @imports) = @_; + my (undef, @imports) = @_; my ($sym, $ch); foreach (@imports) { if (($ch, $sym) = /^([...@\%\*\&])(.+)/) { diff --git a/lib/warnings.pm b/lib/warnings.pm index 10a7cbf..eedbc32 100644 --- a/lib/warnings.pm +++ b/lib/warnings.pm @@ -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. @@ -332,13 +332,8 @@ sub Croaker Carp::croak(@_); } -sub bits -{ - # called from B::Deparse.pm - - push @_, 'all' unless @_; - - my $mask; +sub _bits { + my $mask = shift ; my $catmask ; my $fatal = 0 ; my $no_fatal = 0 ; @@ -364,14 +359,17 @@ sub bits return $mask ; } +sub bits +{ + # called from B::Deparse.pm + push @_, 'all' unless @_ ; + return _bits(undef, @_) ; +} + sub import { shift; - my $catmask ; - my $fatal = 0 ; - my $no_fatal = 0 ; - my $mask = ${^WARNING_BITS} ; if (vec($mask, $Offsets{'all'}, 1)) { @@ -379,27 +377,8 @@ sub import $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1); } - push @_, 'all' unless @_; - - foreach my $word ( @_ ) { - if ($word eq 'FATAL') { - $fatal = 1; - $no_fatal = 0; - } - elsif ($word eq 'NONFATAL') { - $fatal = 0; - $no_fatal = 1; - } - elsif ($catmask = $Bits{$word}) { - $mask |= $catmask ; - $mask |= $DeadBits{$word} if $fatal ; - $mask &= ~($DeadBits{$word}|$All) if $no_fatal ; - } - else - { Croaker("Unknown warnings category '$word'")} - } - - ${^WARNING_BITS} = $mask ; + # Empty @_ is equivalent to @_ = 'all' ; + ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ; } sub unimport @@ -432,11 +411,25 @@ sub unimport my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = (); +sub MESSAGE () { 4 }; +sub FATAL () { 2 }; +sub NORMAL () { 1 }; + sub __chk { my $category ; my $offset ; my $isobj = 0 ; + my $wanted = shift; + my $has_message = $wanted & MESSAGE; + + unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) { + my $sub = (caller 1)[3]; + my $syntax = $has_message ? "[category,] 'message'" : '[category]'; + Croaker("Usage: $sub($syntax)"); + } + + my $message = pop if $has_message; if (@_) { # check the category supplied. @@ -472,8 +465,29 @@ sub __chk $i = _error_loc(); # see where Carp will allocate the error } - my $callers_bitmask = (caller($i))[9] ; - return ($callers_bitmask, $offset, $i) ; + # Defaulting this to 0 reduces complexity in code paths below. + my $callers_bitmask = (caller($i))[9] || 0 ; + + my @results; + foreach my $type (FATAL, NORMAL) { + next unless $wanted & $type; + + push @results, (vec($callers_bitmask, $offset + $type - 1, 1) || + vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1)); + } + + # &enabled and &fatal_enabled + return $results[0] unless $has_message; + + # &warnif, and the category is neither enabled as warning nor as fatal + return if $wanted == (NORMAL | FATAL | MESSAGE) + && !($results[0] || $results[1]); + + require Carp; + Carp::croak($message) if $results[0]; + # will always get here for &warn. will only get here for &warnif if the + # category is enabled + Carp::carp($message); } sub _error_loc { @@ -483,62 +497,27 @@ sub _error_loc { sub enabled { - Croaker("Usage: warnings::enabled([category])") - unless @_ == 1 || @_ == 0 ; - - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - - return 0 unless defined $callers_bitmask ; - return vec($callers_bitmask, $offset, 1) || - vec($callers_bitmask, $Offsets{'all'}, 1) ; + return __chk(NORMAL, @_); } sub fatal_enabled { - Croaker("Usage: warnings::fatal_enabled([category])") - unless @_ == 1 || @_ == 0 ; - - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - - return 0 unless defined $callers_bitmask; - return vec($callers_bitmask, $offset + 1, 1) || - vec($callers_bitmask, $Offsets{'all'} + 1, 1) ; + return __chk(FATAL, @_); } sub warn { - Croaker("Usage: warnings::warn([category,] 'message')") - unless @_ == 2 || @_ == 1 ; - - my $message = pop ; - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - require Carp; - Carp::croak($message) - if vec($callers_bitmask, $offset+1, 1) || - vec($callers_bitmask, $Offsets{'all'}+1, 1) ; - Carp::carp($message) ; + return __chk(FATAL | MESSAGE, @_); } sub warnif { - Croaker("Usage: warnings::warnif([category,] 'message')") - unless @_ == 2 || @_ == 1 ; - - my $message = pop ; - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - - return - unless defined $callers_bitmask && - (vec($callers_bitmask, $offset, 1) || - vec($callers_bitmask, $Offsets{'all'}, 1)) ; - - require Carp; - Carp::croak($message) - if vec($callers_bitmask, $offset+1, 1) || - vec($callers_bitmask, $Offsets{'all'}+1, 1) ; - - Carp::carp($message) ; + return __chk(NORMAL | FATAL | MESSAGE, @_); } +# These are not part of any public interface, so we can delete them to save +# space. +delete $warnings::{$_} foreach qw(NORMAL FATAL MESSAGE); + 1; # ex: set ro: diff --git a/warnings.pl b/warnings.pl index 59d8652..ea6e144 100644 --- a/warnings.pl +++ b/warnings.pl @@ -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. @@ -617,13 +617,8 @@ sub Croaker Carp::croak(@_); } -sub bits -{ - # called from B::Deparse.pm - - push @_, 'all' unless @_; - - my $mask; +sub _bits { + my $mask = shift ; my $catmask ; my $fatal = 0 ; my $no_fatal = 0 ; @@ -649,14 +644,17 @@ sub bits return $mask ; } +sub bits +{ + # called from B::Deparse.pm + push @_, 'all' unless @_ ; + return _bits(undef, @_) ; +} + sub import { shift; - my $catmask ; - my $fatal = 0 ; - my $no_fatal = 0 ; - my $mask = ${^WARNING_BITS} ; if (vec($mask, $Offsets{'all'}, 1)) { @@ -664,27 +662,8 @@ sub import $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1); } - push @_, 'all' unless @_; - - foreach my $word ( @_ ) { - if ($word eq 'FATAL') { - $fatal = 1; - $no_fatal = 0; - } - elsif ($word eq 'NONFATAL') { - $fatal = 0; - $no_fatal = 1; - } - elsif ($catmask = $Bits{$word}) { - $mask |= $catmask ; - $mask |= $DeadBits{$word} if $fatal ; - $mask &= ~($DeadBits{$word}|$All) if $no_fatal ; - } - else - { Croaker("Unknown warnings category '$word'")} - } - - ${^WARNING_BITS} = $mask ; + # Empty @_ is equivalent to @_ = 'all' ; + ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ; } sub unimport @@ -717,11 +696,25 @@ sub unimport my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = (); +sub MESSAGE () { 4 }; +sub FATAL () { 2 }; +sub NORMAL () { 1 }; + sub __chk { my $category ; my $offset ; my $isobj = 0 ; + my $wanted = shift; + my $has_message = $wanted & MESSAGE; + + unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) { + my $sub = (caller 1)[3]; + my $syntax = $has_message ? "[category,] 'message'" : '[category]'; + Croaker("Usage: $sub($syntax)"); + } + + my $message = pop if $has_message; if (@_) { # check the category supplied. @@ -757,8 +750,29 @@ sub __chk $i = _error_loc(); # see where Carp will allocate the error } - my $callers_bitmask = (caller($i))[9] ; - return ($callers_bitmask, $offset, $i) ; + # Defaulting this to 0 reduces complexity in code paths below. + my $callers_bitmask = (caller($i))[9] || 0 ; + + my @results; + foreach my $type (FATAL, NORMAL) { + next unless $wanted & $type; + + push @results, (vec($callers_bitmask, $offset + $type - 1, 1) || + vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1)); + } + + # &enabled and &fatal_enabled + return $results[0] unless $has_message; + + # &warnif, and the category is neither enabled as warning nor as fatal + return if $wanted == (NORMAL | FATAL | MESSAGE) + && !($results[0] || $results[1]); + + require Carp; + Carp::croak($message) if $results[0]; + # will always get here for &warn. will only get here for &warnif if the + # category is enabled + Carp::carp($message); } sub _error_loc { @@ -768,61 +782,26 @@ sub _error_loc { sub enabled { - Croaker("Usage: warnings::enabled([category])") - unless @_ == 1 || @_ == 0 ; - - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - - return 0 unless defined $callers_bitmask ; - return vec($callers_bitmask, $offset, 1) || - vec($callers_bitmask, $Offsets{'all'}, 1) ; + return __chk(NORMAL, @_); } sub fatal_enabled { - Croaker("Usage: warnings::fatal_enabled([category])") - unless @_ == 1 || @_ == 0 ; - - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - - return 0 unless defined $callers_bitmask; - return vec($callers_bitmask, $offset + 1, 1) || - vec($callers_bitmask, $Offsets{'all'} + 1, 1) ; + return __chk(FATAL, @_); } sub warn { - Croaker("Usage: warnings::warn([category,] 'message')") - unless @_ == 2 || @_ == 1 ; - - my $message = pop ; - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - require Carp; - Carp::croak($message) - if vec($callers_bitmask, $offset+1, 1) || - vec($callers_bitmask, $Offsets{'all'}+1, 1) ; - Carp::carp($message) ; + return __chk(FATAL | MESSAGE, @_); } sub warnif { - Croaker("Usage: warnings::warnif([category,] 'message')") - unless @_ == 2 || @_ == 1 ; - - my $message = pop ; - my ($callers_bitmask, $offset, $i) = __chk(@_) ; - - return - unless defined $callers_bitmask && - (vec($callers_bitmask, $offset, 1) || - vec($callers_bitmask, $Offsets{'all'}, 1)) ; - - require Carp; - Carp::croak($message) - if vec($callers_bitmask, $offset+1, 1) || - vec($callers_bitmask, $Offsets{'all'}+1, 1) ; - - Carp::carp($message) ; + return __chk(NORMAL | FATAL | MESSAGE, @_); } +# These are not part of any public interface, so we can delete them to save +# space. +delete $warnings::{$_} foreach qw(NORMAL FATAL MESSAGE); + 1; -- Perl5 Master Repository
