Get the HEK once only in the hot code (class method calls)
Nicholas Clark [Fri, 27 May 2005 09:18:26 +0000 (09:18 +0000)]
p4raw-id: //depot/perl@24594

hv.h
pp_hot.c

diff --git a/hv.h b/hv.h
index 12029ce..c99d479 100644 (file)
--- a/hv.h
+++ b/hv.h
@@ -227,6 +227,8 @@ C<SV*>.
 #define HvNAME(hv)     HvNAME_get(hv)
 /* FIXME - all of these should use a UTF8 aware API, which should also involve
    getting the length. */
+/* This macro may go away without notice.  */
+#define HvNAME_HEK(hv) (((XPVHV *)SvANY(hv))->xhv_aux && (((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) ? ((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name: 0)
 #define HvNAME_get(hv) (((XPVHV *)SvANY(hv))->xhv_aux ? \
                         (((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) ? HEK_KEY(((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) : 0 : 0)
 #define HvNAMELEN_get(hv)      (((XPVHV *)SvANY(hv))->xhv_aux ? \
index 765a8c1..f829f49 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3085,14 +3085,30 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
                sep = p, leaf = p + 2;
        }
        if (!sep || ((sep - name) == 5 && strnEQ(name, "SUPER", 5))) {
-           /* the method name is unqualified or starts with SUPER:: */ 
-           packname = sep ? CopSTASHPV(PL_curcop) :
-               stash ? HvNAME_get(stash) : packname;
-           if (!packname)
+           /* the method name is unqualified or starts with SUPER:: */
+           bool need_strlen = 1;
+           if (sep) {
+               packname = CopSTASHPV(PL_curcop);
+           }
+           else if (stash) {
+               HEK *packhek = HvNAME_HEK(stash);
+               if (packhek) {
+                   packname = HEK_KEY(packhek);
+                   packlen = HEK_LEN(packhek);
+                   need_strlen = 0;
+               } else {
+                   goto croak;
+               }
+           }
+
+           if (!packname) {
+           croak:
                Perl_croak(aTHX_
                           "Can't use anonymous symbol table for method lookup");
-           else
+           }
+           else if (need_strlen)
                packlen = strlen(packname);
+
        }
        else {
            /* the method name is qualified */