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

chromatic at svn.parrot.org chromatic at svn.parrot.org
Thu Apr 1 10:39:50 UTC 2010


Author: chromatic
Date: Thu Apr  1 10:39:49 2010
New Revision: 45367
URL: https://trac.parrot.org/parrot/changeset/45367

Log:
[str] Optimized Parrot_str_concat() to avoid making a COW STRING of the wrong
size, then having to resize it immediately.  Creating a new STRING of the
proper size runs the GC a lot less.

Modified:
   trunk/src/string/api.c

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Thu Apr  1 04:43:50 2010	(r45366)
+++ trunk/src/string/api.c	Thu Apr  1 10:39:49 2010	(r45367)
@@ -515,8 +515,10 @@
     ASSERT_ARGS(Parrot_str_concat)
     if (a && a->strlen) {
         if (b && b->strlen) {
-            STRING *result = Parrot_str_copy(interp, a);
-            Parrot_str_write_COW(interp, result);
+            /* don't make a copy; get the size right from the start */
+            STRING *result = Parrot_str_new_init(interp, NULL,
+                a->strlen + b->strlen, a->encoding, a->charset, Uflags);
+            result = Parrot_str_append(interp, result, a);
             return Parrot_str_append(interp, result, b);
         }
 


More information about the parrot-commits mailing list