This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Slightly simplify some code
authorKarl Williamson <khw@cpan.org>
Fri, 30 Jun 2017 17:19:59 +0000 (11:19 -0600)
committerKarl Williamson <khw@cpan.org>
Thu, 13 Jul 2017 03:14:26 +0000 (21:14 -0600)
This just does a small refactor, which I think makes things easier to
understand.

utf8.c

diff --git a/utf8.c b/utf8.c
index 2472032..ef37514 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -541,19 +541,17 @@ S_does_utf8_overflow(const U8 * const s, const U8 * e)
 
     for (x = s; x < e; x++, y++) {
 
-            /* If this byte is larger than the corresponding highest UTF-8
-                * byte, it overflows */
-            if (UNLIKELY(NATIVE_UTF8_TO_I8(*x) > *y)) {
-                return TRUE;
-            }
-
-            /* If not the same as this byte, it must be smaller, doesn't
-                * overflow */
-            if (LIKELY(NATIVE_UTF8_TO_I8(*x) != *y)) {
-                return FALSE;
-            }
+        if (UNLIKELY(NATIVE_UTF8_TO_I8(*x) == *y)) {
+            continue;
         }
 
+        /* If this byte is larger than the corresponding highest UTF-8 byte,
+         * the sequence overflow; otherwise the byte is less than, and so the
+         * sequence doesn't overflow */
+        return NATIVE_UTF8_TO_I8(*x) > *y;
+
+    }
+
     /* Got to the end and all bytes are the same.  If the input is a whole
      * character, it doesn't overflow.  And if it is a partial character,
      * there's not enough information to tell, so assume doesn't overflow */