From ee14d8a3ccadfaeb16f47187f071914353258bc6 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Mon, 30 Dec 2002 07:28:42 +0000 Subject: [PATCH] Trying to make an iterative assimilate() --- src/bindings.cc | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/bindings.cc b/src/bindings.cc index 481e75d0..404c8267 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -113,37 +113,30 @@ OBBindings::~OBBindings() static void assimilate(BindingTree *parent, BindingTree *node) { - BindingTree *p, *lastsib, *nextparent, *nextnode = node->first_child; + BindingTree *a, *b, *tmp, *last; if (!parent->first_child) { // there are no nodes at this level yet parent->first_child = node; - nextparent = node; + return; } else { - p = lastsib = parent->first_child; - - while (p->next_sibling) { - p = p->next_sibling; - lastsib = p; // finds the last sibling - if (p->binding == node->binding) { - // found an identical binding.. - assert(node->chain && p->chain); - delete node; // kill the one we aren't using - printf("using existing node\n"); - break; + a = parent->first_child; + last = a; + b = node; + while (a->first_child) { + last = a; + if (a->binding != b->binding) { + a = a->next_sibling; + } else { + tmp = b; + b = b->first_child; + delete tmp; + a = a->first_child; } } - if (!p) { - // couldn't find an existing binding, use this new one, and insert it - // into the list - p = lastsib->next_sibling = node; - printf("inserting %s\n", p->text.c_str()); - } - nextparent = p; + last->first_child = b->first_child; + delete b; } - - if (nextnode) - assimilate(nextparent, nextnode); } -- 2.39.2