Skip to content

Commit

Permalink
pp_substr: no need to redo work when cloning the replacement string
Browse files Browse the repository at this point in the history
Currently, when copying the replacement string in preparation for
`sv_utf8_upgrade()`, `pp_substr` calls:

    repl_sv_copy = newSVsv(repl_sv);

However, `repl_sv` was previously checked for GMAGIC, coerced to a
string if necessary, and the char * and length obtained by:

    repl = SvPV_const(repl_sv, repl_len);

We should be able to produce a copy more directly by just doing:

    repl_sv_copy = newSVpvn(repl, repl_len);
  • Loading branch information
richardleach committed Jan 10, 2025
1 parent 77b6579 commit f5f6b47
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,7 @@ PP(pp_substr)
SV* repl_sv_copy = NULL;

if (repl_need_utf8_upgrade) {
repl_sv_copy = newSVsv(repl_sv);
repl_sv_copy = newSVpvn(repl, repl_len);
sv_utf8_upgrade(repl_sv_copy);
repl = SvPV_const(repl_sv_copy, repl_len);
}
Expand Down

0 comments on commit f5f6b47

Please sign in to comment.