This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: lex_stuff_pvn() Use faster UTF-8 variant count
authorKarl Williamson <khw@cpan.org>
Thu, 23 Nov 2017 06:12:37 +0000 (23:12 -0700)
committerKarl Williamson <khw@cpan.org>
Fri, 15 Mar 2019 16:30:28 +0000 (10:30 -0600)
What finally got me to push this commit, since speed really doesn't
matter during compilation, is that this removes a hand-rolled
implementation.

toke.c

diff --git a/toke.c b/toke.c
index f17bfe1..755740d 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -1022,13 +1022,9 @@ Perl_lex_stuff_pvn(pTHX_ const char *pv, STRLEN len, U32 flags)
        if (flags & LEX_STUFF_UTF8) {
            goto plain_copy;
        } else {
-           STRLEN highhalf = 0;    /* Count of variants */
-           const char *p, *e = pv+len;
-           for (p = pv; p != e; p++) {
-               if (! UTF8_IS_INVARIANT(*p)) {
-                    highhalf++;
-                }
-            }
+           STRLEN highhalf = variant_under_utf8_count((U8 *) pv,
+                                                       (U8 *) pv + len);
+            const char *p, *e = pv+len;;
            if (!highhalf)
                goto plain_copy;
            lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len+highhalf);