From: Nicholas Clark <nick@ccl4.org>
Date: Thu, 17 Jun 2010 14:21:24 +0000 (+0100)
Subject: Avoid creating @EXPORT_FAIL in every package using Exporter.
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2d7e78b1bd24d3af5881f95a996405c9c11b1d59;p=p5sagit%2Fp5-mst-13.2.git

Avoid creating @EXPORT_FAIL in every package using Exporter.

Previously, if package INKLE_KLINK is an Exporter, then the Exporter code's
symbolic lookup of \@{"INKLE_KLINK::EXPORT_FAIL"} would cause both that array
and the enclosing typeglob to be instantiated. Now the typeglob and array are
only created if present. (Strictly, if there's something in INKLE_KLINK's
symbol table for EXPORT_FAIL. But likely that will only ever be the array.)

This saves about 200 bytes per package that uses Exporter but does not need an
@EXPORT_FAIL.
---

diff --git a/lib/Exporter.pm b/lib/Exporter.pm
index cd51828..c37f39c 100644
--- a/lib/Exporter.pm
+++ b/lib/Exporter.pm
@@ -9,7 +9,7 @@ require 5.006;
 our $Debug = 0;
 our $ExportLevel = 0;
 our $Verbose ||= 0;
-our $VERSION = '5.64_01';
+our $VERSION = '5.64_02';
 our (%Cache);
 
 sub as_heavy {
@@ -35,9 +35,12 @@ sub import {
   }
 
   # We *need* to treat @{"$pkg\::EXPORT_FAIL"} since Carp uses it :-(
-  my($exports, $fail) = (\@{"$pkg\::EXPORT"}, \@{"$pkg\::EXPORT_FAIL"});
+  my $exports = \@{"$pkg\::EXPORT"};
+  # But, avoid creating things if they don't exist, which saves a couple of
+  # hundred bytes per package processed.
+  my $fail = ${$pkg . '::'}{EXPORT_FAIL} && \@{"$pkg\::EXPORT_FAIL"};
   return export $pkg, $callpkg, @_
-    if $Verbose or $Debug or @$fail > 1;
+    if $Verbose or $Debug or $fail && @$fail > 1;
   my $export_cache = ($Cache{$pkg} ||= {});
   my $args = @_ or @_ = @$exports;
 
@@ -51,7 +54,7 @@ sub import {
   # We bomb out of the loop with last as soon as heavy is set.
   if ($args or $fail) {
     ($heavy = (/\W/ or $args and not exists $export_cache->{$_}
-               or @$fail and $_ eq $fail->[0])) and last
+               or $fail and @$fail and $_ eq $fail->[0])) and last
                  foreach (@_);
   } else {
     ($heavy = /\W/) and last