[svn:parrot] r49190 - trunk/src/pmc
luben at svn.parrot.org
luben at svn.parrot.org
Mon Sep 20 23:56:22 UTC 2010
Author: luben
Date: Mon Sep 20 23:56:22 2010
New Revision: 49190
URL: https://trac.parrot.org/parrot/changeset/49190
Log:
port hash.get_repr to StringBuilder
Modified:
trunk/src/pmc/hash.pmc
Modified: trunk/src/pmc/hash.pmc
==============================================================================
--- trunk/src/pmc/hash.pmc Mon Sep 20 22:45:00 2010 (r49189)
+++ trunk/src/pmc/hash.pmc Mon Sep 20 23:56:22 2010 (r49190)
@@ -373,12 +373,13 @@
}
VTABLE STRING *get_repr() {
- /* TT #1231: Use freeze in get_repr() (for hashes) */
- PMC * const iter = VTABLE_get_iter(INTERP, SELF);
- STRING *res = CONST_STRING(INTERP, "{");
- const INTVAL n = VTABLE_elements(INTERP, SELF);
+ PMC * const iter = VTABLE_get_iter(INTERP, SELF);
+ PMC *sb = Parrot_pmc_new(INTERP, enum_class_StringBuilder);
+ const INTVAL n = VTABLE_elements(INTERP, SELF);
INTVAL j;
+ VTABLE_push_string(INTERP, sb, CONST_STRING(INTERP, "{"));
+
for (j = 0; j < n; ++j) {
STRING * const key = VTABLE_shift_string(INTERP, iter);
char * const key_str = Parrot_str_to_cstring(INTERP, key);
@@ -397,25 +398,22 @@
Parrot_str_free_cstring(key_str);
if (all_digit) {
- res = Parrot_str_concat(INTERP, res, key);
+ VTABLE_push_string(INTERP, sb, key);
}
else {
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "'"));
- res = Parrot_str_concat(INTERP, res, key);
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "'"));
+ VTABLE_push_string(INTERP, sb, CONST_STRING(INTERP, "'"));
+ VTABLE_push_string(INTERP, sb, key);
+ VTABLE_push_string(INTERP, sb, CONST_STRING(INTERP, "'"));
}
-
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, ": "));
+ VTABLE_push_string(INTERP, sb, CONST_STRING(INTERP, ":"));
val = SELF.get_pmc_keyed_str(key);
- res = Parrot_str_concat(INTERP, res, VTABLE_get_string(INTERP, val));
+ VTABLE_push_string(INTERP, sb, VTABLE_get_string(INTERP, val));
if (j < n - 1)
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, ", "));
+ VTABLE_push_string(INTERP, sb, CONST_STRING(INTERP, ", "));
}
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "}"));
-
- return res;
+ return VTABLE_get_string(INTERP, sb);
}
/*
More information about the parrot-commits
mailing list