[svn:parrot] r45592 - branches/immutable_strings_part1/src/pmc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon Apr 12 07:04:17 UTC 2010


Author: chromatic
Date: Mon Apr 12 07:04:17 2010
New Revision: 45592
URL: https://trac.parrot.org/parrot/changeset/45592

Log:
[PMC] Optimized ResizablePMCArray's push_pmc() to avoid unnecessary allocations.

Modified:
   branches/immutable_strings_part1/src/pmc/resizablepmcarray.pmc

Modified: branches/immutable_strings_part1/src/pmc/resizablepmcarray.pmc
==============================================================================
--- branches/immutable_strings_part1/src/pmc/resizablepmcarray.pmc	Mon Apr 12 07:04:13 2010	(r45591)
+++ branches/immutable_strings_part1/src/pmc/resizablepmcarray.pmc	Mon Apr 12 07:04:17 2010	(r45592)
@@ -391,9 +391,14 @@
     }
 
     VTABLE void push_pmc(PMC *value) {
+        const INTVAL size   = PMC_size(SELF);
+        const INTVAL thresh = PMC_threshold(SELF);
 
-        const INTVAL size = PMC_size(SELF);
-        SELF.set_integer_native(size + 1);
+        if (PMC_array(SELF) && size < thresh)
+            PMC_size(SELF) = size + 1;
+        else {
+            SELF.set_integer_native(size + 1);
+        }
         ((PMC **)PMC_array(SELF))[size] = value;
 
         return;


More information about the parrot-commits mailing list