This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove unnecessary temp variable in converting to UTF-8
authorKarl Williamson <public@khwilliamson.com>
Thu, 14 Feb 2013 05:10:19 +0000 (22:10 -0700)
committerKarl Williamson <public@khwilliamson.com>
Thu, 29 Aug 2013 15:55:50 +0000 (09:55 -0600)
These areas of code included a temporary that is unnecessary.

inline.h
regcomp.c
sv.c

index 63a5e06..b95663f 100644 (file)
--- a/inline.h
+++ b/inline.h
@@ -209,15 +209,13 @@ S_append_utf8_from_native_byte(const U8 byte, U8** dest)
     /* Takes an input 'byte' (Latin1 or EBCDIC) and appends it to the UTF-8
      * encoded string at '*dest', updating '*dest' to include it */
 
-    const U8 uv = NATIVE_TO_LATIN1(byte);
-
     PERL_ARGS_ASSERT_APPEND_UTF8_FROM_NATIVE_BYTE;
 
-    if (UNI_IS_INVARIANT(uv))
-        *(*dest)++ = UNI_TO_NATIVE(uv);
+    if (NATIVE_IS_INVARIANT(byte))
+        *(*dest)++ = byte;
     else {
-        *(*dest)++ = UTF8_EIGHT_BIT_HI(uv);
-        *(*dest)++ = UTF8_EIGHT_BIT_LO(uv);
+        *(*dest)++ = UTF8_EIGHT_BIT_HI(byte);
+        *(*dest)++ = UTF8_EIGHT_BIT_LO(byte);
     }
 }
 
index 78773e6..054273d 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -4950,12 +4950,11 @@ S_pat_upgrade_to_utf8(pTHX_ RExC_state_t * const pRExC_state,
     Newx(dst, *plen_p * 2 + 1, U8);
 
     while (s < *plen_p) {
-        const UV uv = NATIVE_TO_ASCII(src[s]);
-        if (UNI_IS_INVARIANT(uv))
-            dst[d]   = (U8)UTF_TO_NATIVE(uv);
+        if (NATIVE_IS_INVARIANT(src[s]))
+            dst[d]   = src[s];
         else {
-            dst[d++] = (U8)UTF8_EIGHT_BIT_HI(uv);
-            dst[d]   = (U8)UTF8_EIGHT_BIT_LO(uv);
+            dst[d++] = UTF8_EIGHT_BIT_HI(src[s]);
+            dst[d]   = UTF8_EIGHT_BIT_LO(src[s]);
         }
         if (n < num_code_blocks) {
             if (!do_end && pRExC_state->code_blocks[n].start == s) {
diff --git a/sv.c b/sv.c
index 8ba0505..ee69bf8 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3469,13 +3469,13 @@ must_be_utf8:
 
                e--;
                while (e >= t) {
-                   const U8 ch = NATIVE8_TO_UNI(*e--);
-                   if (UNI_IS_INVARIANT(ch)) {
-                       *d-- = UNI_TO_NATIVE(ch);
+                   if (NATIVE_IS_INVARIANT(*e)) {
+                       *d-- = *e;
                    } else {
-                       *d-- = (U8)UTF8_EIGHT_BIT_LO(ch);
-                       *d-- = (U8)UTF8_EIGHT_BIT_HI(ch);
+                       *d-- = UTF8_EIGHT_BIT_LO(*e);
+                       *d-- = UTF8_EIGHT_BIT_HI(*e);
                    }
+                    e--;
                }
            }