From f5f6b4773901bb01cbdbfff1d09452d56d6b8f91 Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Fri, 10 Feb 2023 20:19:56 +0000 Subject: [PATCH] pp_substr: no need to redo work when cloning the replacement string 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); --- pp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pp.c b/pp.c index 98edc8f37b92..9beda2d99a83 100644 --- a/pp.c +++ b/pp.c @@ -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); }