This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Change expression to be EBCDIC friendly
authorKarl Williamson <khw@cpan.org>
Thu, 14 Jun 2018 19:35:39 +0000 (13:35 -0600)
committerKarl Williamson <khw@cpan.org>
Thu, 5 Jul 2018 20:47:18 +0000 (14:47 -0600)
This actually does two things: 1) it adds macros that evaluate to no
extra code on ASCII platforms, but allow things to work under EBCDIC;
and 2) it changes to use a ternary conditional.  This may not change
anything, or it may cause the compiler to generate slightly smaller
code at the expense of an extra addition instruction.  I am moving to
inlining this code, and want to make it smaller to enable that to
happen.

utf8.c

diff --git a/utf8.c b/utf8.c
index e3bda6e..68e9f3a 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -1661,14 +1661,10 @@ Perl_utf8n_to_uvchr_msgs(pTHX_ const U8 *s,
     while (s < send && LIKELY(state != PERL_UTF8_DECODE_REJECT)) {
         UV type = dfa_tab_for_perl[*s];
 
-        if (state != 0) {
-            uv = (*s & 0x3fu) | (uv << UTF_ACCUMULATION_SHIFT);
-            state = dfa_tab_for_perl[256 + state + type];
-        }
-        else {
-            uv = (0xff >> type) & (*s);
-            state = dfa_tab_for_perl[256 + type];
-        }
+        uv = (state == 0)
+             ?  ((0xff >> type) & NATIVE_UTF8_TO_I8(*s))
+             : UTF8_ACCUMULATE(uv, *s);
+        state = dfa_tab_for_perl[256 + state + type];
 
         if (state == 0) {
 
@@ -1683,7 +1679,7 @@ Perl_utf8n_to_uvchr_msgs(pTHX_ const U8 *s,
                 goto got_uv;
             }
 
-            return uv;
+            return UNI_TO_NATIVE(uv);
         }
 
         s++;