[svn:parrot] r46207 - branches/codestring/src/pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Sat May 1 20:03:09 UTC 2010
Author: chromatic
Date: Sat May 1 20:03:09 2010
New Revision: 46207
URL: https://trac.parrot.org/parrot/changeset/46207
Log:
[PMC] Made CodeString PMC join its STRING parts during mark() as well as
explicit stringification. This allows the GC to collect all of the other
STRING headers, and the result is a much faster CodeString that's reasonably
parsimonious with memory.
Modified:
branches/codestring/src/pmc/codestring.pmc
Modified: branches/codestring/src/pmc/codestring.pmc
==============================================================================
--- branches/codestring/src/pmc/codestring.pmc Sat May 1 17:15:00 2010 (r46206)
+++ branches/codestring/src/pmc/codestring.pmc Sat May 1 20:03:09 2010 (r46207)
@@ -72,9 +72,14 @@
if (PMC_data(SELF)) {
PMC *linepos, *strings;
+ /* force the join to avoid marking the RPA and lots of STRINGs */
+ STRING *contents = SELF.get_string();
+ UNUSED(contents);
+
GET_ATTR_linepos(INTERP, SELF, linepos);
Parrot_gc_mark_PMC_alive(INTERP, linepos);
+ /* all that's in here now is a single STRING */
GET_ATTR_strings(INTERP, SELF, strings);
Parrot_gc_mark_PMC_alive(INTERP, strings);
}
@@ -119,9 +124,7 @@
GET_ATTR_strings(INTERP, SELF, strings);
/* Loop over the format string, splitting it into chunks
- * for the string builder.
- */
-
+ * for the string builder. */
while (pos >= 0) {
/* Find the next % */
percentPos = Parrot_str_find_index(INTERP, fmt, percent, pos);
@@ -201,16 +204,22 @@
VTABLE STRING *get_string() {
- PMC *strings;
- STRING *result;
+ PMC *strings;
GET_ATTR_strings(INTERP, SELF, strings);
- result = Parrot_str_join(INTERP, CONST_STRING(INTERP, ""), strings);
- /* cache the result to avoid a join the next time. */
- SELF.set_string_native(result);
+ /* avoid unnecessary joins */
+ if (VTABLE_elements(INTERP, strings) <= 1)
+ return VTABLE_get_string_keyed_int(INTERP, strings, 0);
+ else {
+ STRING const *empty = CONST_STRING(INTERP, "");
+ STRING const *result = Parrot_str_join(INTERP, empty, strings);
+
+ /* cache the result to avoid a join the next time. */
+ SELF.set_string_native(result);
- return result;
+ return result;
+ }
}
/*
More information about the parrot-commits
mailing list