- tree *curr_node = this;
- while (curr_node != NULL_POINTER) {
- // make a breadcrumb for getting back to 'here' in the tree.
- tree *way_back = curr_node;
- // our main operation here is to go down a node without using any
- // stack frames. so we just pick the first kid; it's either valid
- // or there are no kids at all.
- curr_node = curr_node->branch(0);
-
- if (curr_node = NULL_POINTER) {
- // wayback has no children, so we can take action.
-
- // if wayback is the same as "this", then we exit from iterations since
- // we've cleaned all the kids out.
- if (way_back == this) {
- break;
- }
+ while (branches()) {
+ // we know we have a branch to work on, due to conditional above.
+ tree *stop_node = branch(0); // don't whack the node we're at until we're done with its kids.
+ tree *curr_node = stop_node;
+ while (curr_node != NULL_POINTER) {
+ // make a breadcrumb for getting back to 'here' in the tree.
+ tree *way_back = curr_node;
+ // our main operation here is to go down a node without using any
+ // stack frames. so we just pick the first kid; it's either valid
+ // or there are no kids at all.
+ curr_node = curr_node->branch(0);
+
+ if (curr_node == NULL_POINTER) {
+ // wayback has no children, so we can take action.
+LOG("tree dtor: can take action on childless node...");
+
+ // if wayback is the same as stop_node, then we exit from iterations since
+ // we've cleaned all the kids out.
+ if (way_back == stop_node) {
+LOG("tree dtor: stopping since at wayback node...");
+ // we can actually delete wayback here, because we are at the stopping point.
+ // and since a tree node whack removes it from its parent, we are clean one branch now.
+ WHACK(way_back);
+LOG("tree dtor: whacked wayback before inner break.");
+ break;
+ }