This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Refactor a portion of to_utf8_case()
authorKarl Williamson <public@khwilliamson.com>
Wed, 6 Jun 2012 21:50:53 +0000 (15:50 -0600)
committerKarl Williamson <public@khwilliamson.com>
Thu, 7 Jun 2012 15:55:50 +0000 (09:55 -0600)
This routine can never return 0, as if there is no case mapping, the
input is used instead.  The code point for that input has already been
derived earlier in the function, so it doesn't have to be recalculated.
And, rearrange the order of things slightly.

utf8.c

diff --git a/utf8.c b/utf8.c
index 5469a8e..3afa69c 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -2419,16 +2419,23 @@ Perl_to_utf8_case(pTHX_ const U8 *p, U8* ustrp, STRLEN *lenp,
         }
     }
 
-    if (!len) { /* There was no mapping defined, which means that the code
-                   point maps to itself */
+    if (len) {
+        if (lenp) {
+            *lenp = len;
+        }
+        return valid_utf8_to_uvchr(ustrp, 0);
+    }
+
+    /* Here, there was no mapping defined, which means that the code point maps
+     * to itself.  Return the inputs */
         len = UTF8SKIP(p);
         Copy(p, ustrp, len, U8);
-    }
 
     if (lenp)
         *lenp = len;
 
-    return len ? valid_utf8_to_uvchr(ustrp, 0) : 0;
+    return uv0;
+
 }
 
 STATIC UV