Skip to content

Commit 25339ee

Browse files
committed
Perl_regexec_flags - create and populate a new SV in one call, not two.
Perl_regexec_flags had these lines to first create a new SV, then assign to it the value(s) of an existing SV: ``` reginfo->sv = newSV_type(SVt_NULL); SvSetSV_nosteal(reginfo->sv, sv); ``` This is two calls into _sv.c_ and, if the existing SV is `SvOK`, will incur an SV upgrade in the process. Those lines are preceded with the comment: `Not newSVsv, either, as it does not COW.` However, the underpinnings of `newSVsv` and variants do support COW nowadays, so we can now just do: ``` reginfo->sv = newSVsv_flags(sv, SV_GMAGIC|SV_NOSTEAL|SV_DO_COW_SVSETSV); ```
1 parent 4072f11 commit 25339ee

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

regexec.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,10 +3863,8 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
38633863
S_cleanup_regmatch_info_aux has executed (registered by
38643864
SAVEDESTRUCTOR_X below). S_cleanup_regmatch_info_aux modifies
38653865
magic belonging to this SV.
3866-
Not newSVsv, either, as it does not COW.
38673866
*/
3868-
reginfo->sv = newSV_type(SVt_NULL);
3869-
SvSetSV_nosteal(reginfo->sv, sv);
3867+
reginfo->sv = newSVsv_flags(sv, SV_GMAGIC|SV_NOSTEAL|SV_DO_COW_SVSETSV);
38703868
SAVEFREESV(reginfo->sv);
38713869
}
38723870

0 commit comments

Comments
 (0)