diff options
author | Karl Williamson <khw@cpan.org> | 2017-11-24 21:56:09 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-11-24 22:10:52 -0700 |
commit | bb1b88dd7be03975ef001e007081e75d83f8cb6f (patch) | |
tree | 797ea6decda2d6f184085b72a0f3caa0fb55225c /sv.c | |
parent | 8cd29efcae02781bf1c9843e66b7b08105659d6b (diff) | |
download | perl-bb1b88dd7be03975ef001e007081e75d83f8cb6f.tar.gz |
sv_utf8_decode: Reverse order of tests for speed
Not that we have a fast is_utf8_invariant_string_loc(), use it first to
quickly find any variants. Then use is_utf8_string() from then on.
This is the reverse order as to how it worked before this commit. This
speeds things up two ways: 1) we use the faster function first, and 2)
use the information it returns to avoid reparsing the string starting at
the beginning.
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -3784,7 +3784,7 @@ Perl_sv_utf8_decode(pTHX_ SV *const sv) PERL_ARGS_ASSERT_SV_UTF8_DECODE; if (SvPOKp(sv)) { - const U8 *start, *c; + const U8 *start, *c, *first_variant; /* The octets may have got themselves encoded - get them back as * bytes @@ -3796,9 +3796,9 @@ Perl_sv_utf8_decode(pTHX_ SV *const sv) * we want to make sure everything inside is valid utf8 first. */ c = start = (const U8 *) SvPVX_const(sv); - if (!is_utf8_string(c, SvCUR(sv))) - return FALSE; - if (! is_utf8_invariant_string(c, SvCUR(sv))) { + if (! is_utf8_invariant_string_loc(c, SvCUR(sv), &first_variant)) { + if (!is_utf8_string(first_variant, SvCUR(sv) - (first_variant -c))) + return FALSE; SvUTF8_on(sv); } if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) { |