diff options
author | Loren Merritt <pengvado@videolan.org> | 2022-07-14 00:09:06 +0000 |
---|---|---|
committer | ℕicolas ℝ <nicolas@atoomic.org> | 2022-07-20 15:03:07 -0600 |
commit | be76ad45a5a937ec83906e666e2318c0351115b4 (patch) | |
tree | 8bc97d8c1b33b15fe81ea192c063f270853b3918 /pp_hot.c | |
parent | 7d47ba27dfa1ef9db23c4e6f934b0698d7fd539f (diff) | |
download | perl-be76ad45a5a937ec83906e666e2318c0351115b4.tar.gz |
pp_subst: optimize by not calling utf8_length
Length just isn't needed, and often took more cpu-time than the actual regex.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -4250,7 +4250,6 @@ PP(pp_subst) STRLEN len; int force_on_match = 0; const I32 oldsave = PL_savestack_ix; - STRLEN slen; bool doutf8 = FALSE; /* whether replacement is in utf8 */ #ifdef PERL_ANY_COW bool was_cow; @@ -4316,10 +4315,12 @@ PP(pp_subst) DIE(aTHX_ "panic: pp_subst, pm=%p, orig=%p", pm, orig); strend = orig + len; - slen = DO_UTF8(TARG) ? utf8_length((U8*)orig, (U8*)strend) : len; - maxiters = 2 * slen + 10; /* We can match twice at each - position, once with zero-length, - second time with non-zero. */ + /* We can match twice at each position, once with zero-length, + * second time with non-zero. + * Don't handle utf8 specially; we can use length-in-bytes as an + * upper bound on length-in-characters, and avoid the cpu-cost of + * computing a tighter bound. */ + maxiters = 2 * len + 10; /* handle the empty pattern */ if (!RX_PRELEN(rx) && PL_curpm && !prog->mother_re) { |