From: Nicholas Clark Date: Fri, 27 May 2005 09:18:26 +0000 (+0000) Subject: Get the HEK once only in the hot code (class method calls) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9b9d0b15bd9c5c0115200324ab9b04803069c7ce;p=p5sagit%2Fp5-mst-13.2.git Get the HEK once only in the hot code (class method calls) p4raw-id: //depot/perl@24594 --- diff --git a/hv.h b/hv.h index 12029ce..c99d479 100644 --- a/hv.h +++ b/hv.h @@ -227,6 +227,8 @@ C. #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 ? \ diff --git a/pp_hot.c b/pp_hot.c index 765a8c1..f829f49 100644 --- 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 */