utf8.c: Don't use slower general-purpose function
authorKarl Williamson <public@khwilliamson.com>
Sat, 6 Apr 2013 18:54:42 +0000 (12:54 -0600)
committerKarl Williamson <public@khwilliamson.com>
Thu, 29 Aug 2013 15:56:05 +0000 (09:56 -0600)
There is a macro that accomplishes the same task for a two byte UTF-8
encoded character, and avoids the overhead of the general purpose
function call.

utf8.c

diff --git a/utf8.c b/utf8.c
index 64da27d..7e87a0d 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -1280,9 +1280,13 @@ Perl_utf8_to_bytes(pTHX_ U8 *s, STRLEN *len)
 
     d = s = save;
     while (s < send) {
-        STRLEN ulen;
-        *d++ = (U8)utf8_to_uvchr_buf(s, send, &ulen);
-        s += ulen;
+       U8 c = *s++;
+       if (! UTF8_IS_INVARIANT(c)) {
+           /* Then it is two-byte encoded */
+           c = TWO_BYTE_UTF8_TO_NATIVE(c, *s);
+            s++;
+       }
+       *d++ = c;
     }
     *d = '\0';
     *len = d - save;