From: Nicholas Clark Date: Thu, 18 Oct 2007 18:06:29 +0000 (+0000) Subject: Eliminate some uses of sv_setpv() where we already know the length. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=49a54bbe5e246f5f51e51453d9cc5a19e72a4433;p=p5sagit%2Fp5-mst-13.2.git Eliminate some uses of sv_setpv() where we already know the length. Donate the prototype buffer to the CV in Perl_gv_init(), rather than setting a copy, and immediately free()ing the original. p4raw-id: //depot/perl@32136 --- diff --git a/gv.c b/gv.c index d34d043..24dabf6 100644 --- a/gv.c +++ b/gv.c @@ -214,6 +214,7 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi) const U32 old_type = SvTYPE(gv); const bool doproto = old_type > SVt_NULL; const char * const proto = (doproto && SvPOK(gv)) ? SvPVX_const(gv) : NULL; + const STRLEN protolen = proto ? SvCUR(gv) : 0; SV *const has_constant = doproto && SvROK(gv) ? SvRV(gv) : NULL; const U32 exported_constant = has_constant ? SvPCS_IMPORTED(gv) : 0; @@ -280,8 +281,8 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi) CvFILE_set_from_cop(GvCV(gv), PL_curcop); CvSTASH(GvCV(gv)) = PL_curstash; if (proto) { - sv_setpv((SV*)GvCV(gv), proto); - Safefree(proto); + sv_usepvn_flags((SV*)GvCV(gv), proto, protolen, + SV_HAS_TRAILING_NUL); } } } diff --git a/toke.c b/toke.c index f8d207c..8487397 100644 --- a/toke.c +++ b/toke.c @@ -3694,10 +3694,10 @@ Perl_yylex(pTHX) if (PL_madskills) PL_faketokens = 1; #endif - sv_setpv(PL_linestr, - (const char *) - (PL_minus_p - ? ";}continue{print;}" : ";}")); + if (PL_minus_p) + sv_setpvs(PL_linestr, ";}continue{print;}"); + else + sv_setpvs(PL_linestr, ";}"); PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); PL_last_lop = PL_last_uni = NULL; @@ -5534,10 +5534,10 @@ Perl_yylex(pTHX) while (*proto == ';') proto++; if (*proto == '&' && *s == '{') { - sv_setpv(PL_subname, - (const char *) - (PL_curstash ? - "__ANON__" : "__ANON__::__ANON__")); + if (PL_curstash) + sv_setpvs(PL_subname, "__ANON__"); + else + sv_setpvs(PL_subname, "__ANON__::__ANON__"); PREBLOCK(LSTOPSUB); } } @@ -6758,9 +6758,10 @@ Perl_yylex(pTHX) } #endif if (!have_name) { - sv_setpv(PL_subname, - (const char *) - (PL_curstash ? "__ANON__" : "__ANON__::__ANON__")); + if (PL_curstash) + sv_setpvs(PL_subname, "__ANON__"); + else + sv_setpvs(PL_subname, "__ANON__::__ANON__"); TOKEN(ANONSUB); } #ifndef PERL_MAD