[svn:parrot] r44041 - trunk/src/string

chromatic at svn.parrot.org chromatic at svn.parrot.org
Tue Feb 16 19:32:48 UTC 2010


Author: chromatic
Date: Tue Feb 16 19:32:48 2010
New Revision: 44041
URL: https://trac.parrot.org/parrot/changeset/44041

Log:
[str] Simplified Parrot_str_concat() to avoid creating more STRING headers than
necessary; this ought to improve performance in loops that HLLs often produce.
It's less code, anyhow.

Modified:
   trunk/src/string/api.c

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Tue Feb 16 19:32:45 2010	(r44040)
+++ trunk/src/string/api.c	Tue Feb 16 19:32:48 2010	(r44041)
@@ -496,21 +496,9 @@
     ASSERT_ARGS(Parrot_str_concat)
     if (a && a->strlen) {
         if (b && b->strlen) {
-            const ENCODING *enc;
-            const CHARSET  *cs = string_rep_compatible(interp, a, b, &enc);
-            STRING         *result;
-
-            if (!cs) {
-                cs  = a->charset;
-                enc = a->encoding;
-            }
-            result = Parrot_str_new_init(interp, NULL, a->bufused + b->bufused,
-                        enc, cs, 0);
-
-            result = Parrot_str_append(interp, result, a);
-            result = Parrot_str_append(interp, result, b);
-
-            return result;
+            STRING *result = Parrot_str_copy(interp, a);
+            Parrot_str_write_COW(interp, result);
+            return Parrot_str_append(interp, result, b);
         }
 
         return Parrot_str_copy(interp, a);
@@ -573,10 +561,10 @@
     }
     else {
         /* upgrade strings for concatenation */
-        enc = (a->encoding == Parrot_utf16_encoding_ptr ||
-                  b->encoding == Parrot_utf16_encoding_ptr ||
-                  a->encoding == Parrot_ucs2_encoding_ptr ||
-                  b->encoding == Parrot_ucs2_encoding_ptr)
+        enc = (a->encoding == Parrot_utf16_encoding_ptr
+           ||  b->encoding == Parrot_utf16_encoding_ptr
+           ||  a->encoding == Parrot_ucs2_encoding_ptr
+           ||  b->encoding == Parrot_ucs2_encoding_ptr)
               ? Parrot_utf16_encoding_ptr
               : Parrot_utf8_encoding_ptr;
 


More information about the parrot-commits mailing list