From f7f919a02477385250997b98fe25f99657653150 Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Fri, 3 Dec 2021 00:10:51 +0000 Subject: Misc microoptimizations when dealing with new SVs In a few places, SVs can be created more efficiently or new SVs can be assigned to more efficiently. Small changes included: * Use sv_setpvn_fresh instead of sv_setpvn * Use sv_mortalcopy_flags instead of sv_newmortal + sv_setsv_flags * newSVsv_flags instead of newSV + sv_setsv_flags * sv_newmortal instead of sv_2mortal(newSV(0)) * Remove a SvGROW(sv, 257) following a newSV(257) --- pp_hot.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'pp_hot.c') diff --git a/pp_hot.c b/pp_hot.c index f22628617f..477cdd48b8 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1077,16 +1077,15 @@ PP(pp_multiconcat) /* if both args are the same magical value, make one a copy */ if (left == right && SvGMAGICAL(left)) { - left = sv_newmortal(); + SV * targetsv = right; /* Print the uninitialized warning now, so it includes the * variable name. */ if (!SvOK(right)) { if (ckWARN(WARN_UNINITIALIZED)) report_uninit(right); - sv_setbool(left, FALSE); + targetsv = &PL_sv_no; } - else - sv_setsv_flags(left, right, 0); + left = sv_mortalcopy_flags(targetsv, 0); SvGETMAGIC(right); } } @@ -2407,13 +2406,10 @@ PP(pp_aassign) } else { SV *nsv; - /* do get before newSV, in case it dies and leaks */ - SvGETMAGIC(rsv); - nsv = newSV(0); /* see comment in S_aassign_copy_common about * SV_NOSTEAL */ - sv_setsv_flags(nsv, rsv, - (SV_DO_COW_SVSETSV|SV_NOSTEAL)); + nsv = newSVsv_flags(rsv, + (SV_DO_COW_SVSETSV|SV_NOSTEAL|SV_GMAGIC)); rsv = *svp = nsv; } @@ -2531,13 +2527,10 @@ PP(pp_aassign) } else { SV *nsv; - /* do get before newSV, in case it dies and leaks */ - SvGETMAGIC(rsv); - nsv = newSV(0); /* see comment in S_aassign_copy_common about * SV_NOSTEAL */ - sv_setsv_flags(nsv, rsv, - (SV_DO_COW_SVSETSV|SV_NOSTEAL)); + nsv = newSVsv_flags(rsv, + (SV_DO_COW_SVSETSV|SV_NOSTEAL|SV_GMAGIC)); rsv = *svp = nsv; } -- cgit v1.2.1