From 04c3abc96778ee1f1908d310f8576f344bb3c0ca Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 11 Apr 2008 16:48:05 -0600 Subject: [PATCH] fix broken thread tree traversal in machine.cpp --- src/machine.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index a06fd154ea..1c878a8627 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -22,15 +22,9 @@ namespace { bool find(Thread* t, Thread* o) { - if (t == o) return true; - - for (Thread* p = t->peer; p; p = p->peer) { - if (p == o) return true; - } - - if (t->child) return find(t->child, o); - - return false; + return (t == o) + or (t->peer and find(t->peer, o)) + or (t->child and find(t->child, o)); } void @@ -48,11 +42,7 @@ count(Thread* t, Thread* o) unsigned c = 0; if (t != o) ++ c; - - for (Thread* p = t->peer; p; p = p->peer) { - c += count(p, o); - } - + if (t->peer) c += count(t->peer, o); if (t->child) c += count(t->child, o); return c; @@ -62,12 +52,8 @@ Thread** fill(Thread* t, Thread* o, Thread** array) { if (t != o) *(array++) = t; - - for (Thread* p = t->peer; p; p = p->peer) { - array = fill(p, o, array); - } - - if (t->child) array = fill(t->child, o, array); + if (t->peer) fill(t->peer, o, array); + if (t->child) fill(t->child, o, array); return array; }