This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Remove redundant unlikely branches
authorKarl Williamson <public@khwilliamson.com>
Tue, 30 Oct 2012 16:15:38 +0000 (10:15 -0600)
committerKarl Williamson <public@khwilliamson.com>
Sun, 11 Nov 2012 18:50:11 +0000 (11:50 -0700)
The 2 lines removed in each function provide an early exit if the input
is malformed UTF-8.  Other code executed later makes the same test.
But most inputs are going to be well-formed, so the test will almost
always fail, so will slow things up.

utf8.c

diff --git a/utf8.c b/utf8.c
index 184e429..3ee9f2d 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -383,8 +383,6 @@ Perl_is_utf8_string(const U8 *s, STRLEN len)
         if (UTF8_IS_INVARIANT(*x)) {
            x++;
         }
-        else if (!UTF8_IS_START(*x))
-            return FALSE;
         else {
              /* ... and call is_utf8_char() only if really needed. */
             const STRLEN c = UTF8SKIP(x);
@@ -447,8 +445,6 @@ Perl_is_utf8_string_loclen(const U8 *s, STRLEN len, const U8 **ep, STRLEN *el)
         /* Inline the easy bits of is_utf8_char() here for speed... */
         if (UTF8_IS_INVARIANT(*x))
             next_char_ptr = x + 1;
-        else if (!UTF8_IS_START(*x))
-            goto out;
         else {
             /* ... and call is_utf8_char() only if really needed. */
             c = UTF8SKIP(x);