summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-31 21:38:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-31 21:38:18 -0700
commit5d9e217bb248015823c948010c1f0b47efe2cdb4 (patch)
tree5b6d1df7e8cbb8c15dd55688a41f95182f1a342c /hash.c
parent4b4ef6dfcf12e1db846b26a3b812aa010360d62f (diff)
downloadtxr-5d9e217bb248015823c948010c1f0b47efe2cdb4.tar.gz
txr-5d9e217bb248015823c948010c1f0b47efe2cdb4.tar.bz2
txr-5d9e217bb248015823c948010c1f0b47efe2cdb4.zip
Use obj_print_impl for printing hash contents.
* hash.c (print_key_val): Static function removed. (hash_print_op): Don't use maphash over print_key_val to print hash tables. Use open-coded iteration and printing with calls to obj_print_impl. This was occassioned by a bug in circle printing. The use of obj_print by hash_print_op resembles the actions of a custom print method on a structure. A bug showed up which is masked by refactoring to more direct recursion via obj_print_impl. (The bug still has to be fixed, though).
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/hash.c b/hash.c
index ab2a0fd9..b2bbe0ec 100644
--- a/hash.c
+++ b/hash.c
@@ -248,17 +248,6 @@ cnum cobj_hash_op(val obj, int *count)
abort();
}
-static val print_key_val(val out, val key, val value)
-{
- width_check(out, chr(' '));
-
- if (value)
- format(out, lit("(~s ~s)"), key, value, nao);
- else
- format(out, lit("(~s)"), key, nao);
- return nil;
-}
-
static val hash_equal_op(val left, val right)
{
uses_or2;
@@ -418,7 +407,24 @@ static void hash_print_op(val hash, val out, val pretty, struct strm_ctx *ctx)
obj_print_impl(h->userdata, out, pretty, ctx);
}
put_string(lit(")"), out);
- maphash(curry_123_23(func_n3(print_key_val), out), hash);
+ {
+ val iter = hash_begin(hash), cell;
+ while ((cell = hash_next(iter))) {
+ val key = car(cell);
+ val value = cdr(cell);
+ width_check(out, chr(' '));
+
+ put_string(lit("("), out);
+ obj_print_impl(key, out, pretty, ctx);
+
+ if (value) {
+ put_string(lit(" "), out);
+ obj_print_impl(value, out, pretty, ctx);
+ }
+
+ put_string(lit(")"), out);
+ }
+ }
put_string(lit(")"), out);
set_indent_mode(out, save_mode);