This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pad.c: Use PadnamelistMAXNAMED in another place
authorFather Chrysostomos <sprout@cpan.org>
Wed, 27 Aug 2014 06:21:43 +0000 (23:21 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 28 Aug 2014 20:04:17 +0000 (13:04 -0700)
This will speed up pad lookup a little more.  This could be considered
a follow-up to commit 7db6405c.

There is a hack that allows an ‘our’ variable to be found in the pad
in the statement in which it is declared, to avoid a warning (since
the fallback would be to look up the very same variable in the current
package anyway).

This commit applies the PadnamelistMAXNAMED optimisation to that code
path.  This is how that optimisation works:  When named slots are
allocated in the pad, PadnamelistMAXNAMED is set, so that, when
searching for named items in the pad, we don’t have to search the
whole thing if there are many constants or GVs at the end.

Recent commits slowed down t/re/uniprops.t considerably.  This was the remaining bottleneck.

We could actually skip the whole ‘our’ hack for subroutine lookup
(since the warning it avoids doesn’t apply to subroutines anyway).  In
fact, the next commit will do that.  But this optimisation is worth-
while anyway.

pad.c

diff --git a/pad.c b/pad.c
index c333d6a..1c06f2f 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -972,7 +972,7 @@ Perl_pad_findmy_pvn(pTHX_ const char *namepv, STRLEN namelen, U32 flags)
 
     nameav = PadlistARRAY(CvPADLIST(PL_compcv))[0];
     name_svp = AvARRAY(nameav);
-    for (offset = AvFILLp(nameav); offset > 0; offset--) {
+    for (offset = PadnamelistMAXNAMED(nameav); offset > 0; offset--) {
         const SV * const namesv = name_svp[offset];
        if (namesv && PadnameLEN(namesv) == namelen
            && !SvFAKE(namesv)