From: Nicholas Clark Date: Fri, 3 Jun 2005 11:06:36 +0000 (+0000) Subject: Use newSVhek where we're generating SVs from package names X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5aaec2b4ba9ed3b1a9d1569e09bc40d19ec30f8c;p=p5sagit%2Fp5-mst-13.2.git Use newSVhek where we're generating SVs from package names p4raw-id: //depot/perl@24697 --- diff --git a/op.c b/op.c index 949d8f4..b5946fa 100644 --- a/op.c +++ b/op.c @@ -1534,10 +1534,7 @@ S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs, bool for_my) /* fake up C */ ENTER; /* need to protect against side-effects of 'use' */ SAVEINT(PL_expect); - if (stash) - stashsv = newSVpvn(HvNAME_get(stash), HvNAMELEN_get(stash)); - else - stashsv = &PL_sv_no; + stashsv = stash ? newSVhek(HvNAME_HEK(stash)) : &PL_sv_no; #define ATTRSMODULE "attributes" #define ATTRSMODULE_PM "attributes.pm" @@ -1587,10 +1584,8 @@ S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp) pack = newSVOP(OP_CONST, 0, newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1)); /* Build up the real arg-list. */ - if (stash) - stashsv = newSVpvn(HvNAME_get(stash), HvNAMELEN_get(stash)); - else - stashsv = &PL_sv_no; + stashsv = stash ? newSVhek(HvNAME_HEK(stash)) : &PL_sv_no; + arg = newOP(OP_PADSV, 0); arg->op_targ = target->op_targ; arg = prepend_elem(OP_LIST, diff --git a/pp.c b/pp.c index 97a5cfb..2014f6f 100644 --- a/pp.c +++ b/pp.c @@ -600,9 +600,8 @@ PP(pp_gelem) break; case 'P': if (strEQ(elem2, "ACKAGE")) { - const char *name = HvNAME_get(GvSTASH(gv)); - sv = newSVpvn(name ? name : "__ANON__", - name ? HvNAMELEN_get(GvSTASH(gv)) : 8); + const HEK *hek = HvNAME_HEK(GvSTASH(gv)); + sv = hek ? newSVhek(hek) : newSVpvn("__ANON__", 8); } break; case 'S': diff --git a/sv.c b/sv.c index 546df0a..bb7f037 100644 --- a/sv.c +++ b/sv.c @@ -7606,7 +7606,8 @@ Perl_newSVpvn(pTHX_ const char *s, STRLEN len) =for apidoc newSVpv_hek Creates a new SV from the hash key structure. It will generate scalars that -point to the shared string table where possible. +point to the shared string table where possible. Returns a new (undefined) +SV if the hek is NULL. =cut */ @@ -7614,6 +7615,13 @@ point to the shared string table where possible. SV * Perl_newSVhek(pTHX_ const HEK *hek) { + if (!hek) { + SV *sv; + + new_SV(sv); + return sv; + } + if (HEK_LEN(hek) == HEf_SVKEY) { return newSVsv(*(SV**)HEK_KEY(hek)); } else { diff --git a/toke.c b/toke.c index 26b7f3d..d09d191 100644 --- a/toke.c +++ b/toke.c @@ -4346,8 +4346,7 @@ Perl_yylex(pTHX) case KEY___PACKAGE__: yylval.opval = (OP*)newSVOP(OP_CONST, 0, (PL_curstash - ? newSVpvn(HvNAME_get(PL_curstash), - HvNAMELEN_get(PL_curstash)) + ? newSVhek(HvNAME_HEK(PL_curstash)) : &PL_sv_undef)); TERM(THING); @@ -5540,9 +5539,7 @@ S_pending_ident(pTHX) /* build ops for a bareword */ HV *stash = PAD_COMPNAME_OURSTASH(tmp); HEK *stashname = HvNAME_HEK(stash); - SV *sym = stashname - ? newSVpvn(HEK_KEY(stashname), HEK_LEN(stashname)) - : newSVpvn(0, 0); + SV *sym = newSVhek(stashname); sv_catpvn(sym, "::", 2); sv_catpv(sym, PL_tokenbuf+1); yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); @@ -9744,10 +9741,7 @@ S_scan_inputsymbol(pTHX_ char *start) if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { HV *stash = PAD_COMPNAME_OURSTASH(tmp); HEK *stashname = HvNAME_HEK(stash); - SV *sym = sv_2mortal(stashname - ? newSVpvn(HEK_KEY(stashname), - HEK_LEN(stashname)) - : newSVpvn(0, 0)); + SV *sym = sv_2mortal(newSVhek(stashname)); sv_catpvn(sym, "::", 2); sv_catpv(sym, d+1); d = SvPVX(sym);