This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Extra branch to avoid others in the typical case
authorKarl Williamson <public@khwilliamson.com>
Sun, 29 Apr 2012 00:40:40 +0000 (18:40 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 22 May 2012 14:24:19 +0000 (08:24 -0600)
This test eliminates all code points less than U+D800 from having to be
checked more than once, at the expense of an extra test for code points
that are larger

utf8.c

diff --git a/utf8.c b/utf8.c
index 83d2397..ce0820d 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -137,7 +137,10 @@ Perl_uvuni_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
 {
     PERL_ARGS_ASSERT_UVUNI_TO_UTF8_FLAGS;
 
-    if (ckWARN4_d(WARN_UTF8, WARN_SURROGATE, WARN_NON_UNICODE, WARN_NONCHAR)) {
+    /* 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))
+    {
        if (UNICODE_IS_SURROGATE(uv)) {
            if (flags & UNICODE_WARN_SURROGATE) {
                Perl_ck_warner_d(aTHX_ packWARN(WARN_SURROGATE),