summaryrefslogtreecommitdiffstats
path: root/tree.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-30 09:07:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-30 09:07:20 -0700
commitecf92c96cc73cfc25a0ab98a6a0070c87465bc22 (patch)
treebe5e5f1bee013ee63d85354114b3d9a137baddad /tree.c
parentf3225cb0e6bfaf17709b0c171e77cd58fb198ce1 (diff)
downloadtxr-ecf92c96cc73cfc25a0ab98a6a0070c87465bc22.tar.gz
txr-ecf92c96cc73cfc25a0ab98a6a0070c87465bc22.tar.bz2
txr-ecf92c96cc73cfc25a0ab98a6a0070c87465bc22.zip
tree: different fix for dummy node issue.
Let's restore the previous commit and fix it differently. The real problem is that the tn_flatten function does not need to use the set macro. When the flattened tree is rebuilt with tn_build_tree, every left and right link of every node is set at that time. That function uses the set macro, so all is well. The dummy node is not pulled into the rebuild, so it doesn't cause any problem; the dummy node is only mutated in tn_flatten. This is a better fix not only because tn_flatten is now more efficient. It is important for the dummy node to look like it is a generation zero object. The dummy node ends up as the pseudo-root of the tree, which means that it if it looks like it is in generation 1, all generation 0 below it will be wastefully checked by the garbage collector. * tree.c (tn_flatten): Do not use the set macro. Just use straight assignment to convert the tree into a linked list. (tr_rebuild): Restore dummy node to be all zeros.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/tree.c b/tree.c
index ee1d37c4..9cfefdbf 100644
--- a/tree.c
+++ b/tree.c
@@ -303,7 +303,7 @@ static val tn_flatten(val x, val y)
{
if (x == nil)
return y;
- set(mkloc(x->tn.right, x), tn_flatten(x->tn.right, y));
+ x->tn.right = tn_flatten(x->tn.right, y);
return tn_flatten(x->tn.left, x);
}
@@ -327,7 +327,7 @@ static void tr_rebuild(val tree, struct tree *tr, val node,
val parent, ucnum size)
{
#if CONFIG_GEN_GC
- obj_t dummy = { { TNOD, 0, 1, { 0 }, 0 } };
+ obj_t dummy = { { TNOD, 0, 0, { 0 }, 0 } };
#else
obj_t dummy = { { TNOD, { 0 }, 0 } };
#endif