all repos — openbox @ ee14d8a3ccadfaeb16f47187f071914353258bc6

openbox fork - make it a bit more like ryudo

Trying to make an iterative assimilate()
Derek Foreman manmower@gmail.com
commit

ee14d8a3ccadfaeb16f47187f071914353258bc6

parent

624a06fdffadfadbf6ac14068bbd329cc0a5834f

1 files changed, 16 insertions(+), 23 deletions(-)

jump to
M src/bindings.ccsrc/bindings.cc

@@ -113,37 +113,30 @@

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); }