In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/392582f8c00033c1199d338baf72f42bbd9ef2dc?hp=94a5f6597322b09798789257ed58175d9e7462a7>
- Log ----------------------------------------------------------------- commit 392582f8c00033c1199d338baf72f42bbd9ef2dc Author: David Mitchell <[email protected]> Date: Wed Nov 9 11:50:35 2016 +0000 Perl_do_vop(): enhance "avoid sv_catpvn" TonyC's recent commit v5.25.6-172-gdc529e6 updated do_vop() to avoid doing a sv_catpvn() when the left and destination SVs are the same. As well as being more efficient, it is needed, as a recent change to sv_catpvn() made it more likely to grow and realloc the buffer, meaning the copy()'s src buffer had been freed. This commit represents my parallel attempt to fix the same issue; I'm replacing Tony's version with mine as it is logically more comprehensive: it copes with the dest being the same as the right arg as well as the left, and checks for string pointers being equal rather than sv's being equal. Neither of these make any difference currently, but they could in theory (although unlikely) catch some future change in usage. RT #129995 ----------------------------------------------------------------------- Summary of changes: doop.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/doop.c b/doop.c index bc23c9e..e4b2cd8 100644 --- a/doop.c +++ b/doop.c @@ -1216,21 +1216,20 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right) *dc++ = *lc++ | *rc++; mop_up: len = lensave; - if (rightlen > len) - sv_catpvn_nomg(sv, rsave + len, rightlen - len); - else if (leftlen > (STRLEN)len) { - if (sv == left) { - /* sv_catpvn() might move the source from under us, - and the data is already in place, just adjust to - include it */ - SvCUR_set(sv, leftlen); - *SvEND(sv) = '\0'; - } + if (rightlen > len) { + if (dc == rc) + SvCUR(sv) = rightlen; + else + sv_catpvn_nomg(sv, rsave + len, rightlen - len); + } + else if (leftlen > len) { + if (dc == lc) + SvCUR(sv) = leftlen; else sv_catpvn_nomg(sv, lsave + len, leftlen - len); } - else - *SvEND(sv) = '\0'; + *SvEND(sv) = '\0'; + break; } } -- Perl5 Master Repository
