utf8.c: Move some code around for speed
authorKarl Williamson <public@khwilliamson.com>
Wed, 26 Jun 2013 21:30:59 +0000 (15:30 -0600)
committerKarl Williamson <public@khwilliamson.com>
Thu, 29 Aug 2013 15:56:09 +0000 (09:56 -0600)
This is a micro optimization.  We now check for a common case and return
if found, before checking for a relatively uncommon case.

utf8.c

diff --git a/utf8.c b/utf8.c
index 20d7aca..1647f18 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -100,6 +100,11 @@ Perl_uvoffuni_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
 {
     PERL_ARGS_ASSERT_UVOFFUNI_TO_UTF8_FLAGS;
 
+    if (UNI_IS_INVARIANT(uv)) {
+       *d++ = (U8) LATIN1_TO_NATIVE(uv);
+       return d;
+    }
+
     /* The first problematic code point is the first surrogate */
     if (uv >= UNICODE_SURROGATE_FIRST
         && ckWARN4_d(WARN_UTF8, WARN_SURROGATE, WARN_NON_UNICODE, WARN_NONCHAR))
@@ -137,12 +142,9 @@ Perl_uvoffuni_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
            }
        }
     }
-    if (UNI_IS_INVARIANT(uv)) {
-       *d++ = (U8) LATIN1_TO_NATIVE(uv);
-       return d;
-    }
+
 #if defined(EBCDIC)
-    else {
+    {
        STRLEN len  = OFFUNISKIP(uv);
        U8 *p = d+len-1;
        while (p > d) {