From: Bart Van Assche Date: Thu, 6 Mar 2008 18:02:37 +0000 (+0000) Subject: Cleaned up vc_min() and vc_combine() implementations. X-Git-Tag: svn/VALGRIND_3_4_0~961 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a10a37c2b172de7bc612eaad787957f42855800b;p=thirdparty%2Fvalgrind.git Cleaned up vc_min() and vc_combine() implementations. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7578 --- diff --git a/exp-drd/drd_vc.c b/exp-drd/drd_vc.c index 6e887d07e5..19476efda4 100644 --- a/exp-drd/drd_vc.c +++ b/exp-drd/drd_vc.c @@ -135,44 +135,20 @@ Bool vc_ordered(const VectorClock* const vc1, } /** Compute elementwise minimum. */ -void vc_min(VectorClock* const result, - const VectorClock* const rhs) +void vc_min(VectorClock* const result, const VectorClock* const rhs) { unsigned i; unsigned j; - unsigned shared; - unsigned new_size; tl_assert(result); tl_assert(rhs); - /* First count the number of shared thread ID's. */ - j = 0; - shared = 0; - for (i = 0; i < result->size; i++) - { - while (j < rhs->size && rhs->vc[j].threadid < result->vc[i].threadid) - j++; - if (j >= rhs->size) - break; - if (result->vc[i].threadid == rhs->vc[j].threadid) - shared++; - } - - vc_check(result); - - new_size = result->size + rhs->size - shared; - if (new_size > result->capacity) - vc_reserve(result, new_size); - vc_check(result); /* Next, combine both vector clocks into one. */ i = 0; for (j = 0; j < rhs->size; j++) { - vc_check(result); - while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid) { /* Thread ID is missing in second vector clock. Clear the count. */ @@ -181,15 +157,9 @@ void vc_min(VectorClock* const result, } if (i >= result->size) { - result->size++; - result->vc[i] = rhs->vc[j]; - vc_check(result); - } - else if (result->vc[i].threadid > rhs->vc[j].threadid) - { - /* Thread ID is missing in first vector clock. Leave out. */ + break; } - else + if (result->vc[i].threadid <= rhs->vc[j].threadid) { /* The thread ID is present in both vector clocks. Compute the minimum */ /* of vc[i].count and vc[j].count. */ @@ -198,7 +168,6 @@ void vc_min(VectorClock* const result, { result->vc[i].count = rhs->vc[j].count; } - vc_check(result); } } vc_check(result); @@ -243,15 +212,12 @@ void vc_combine(VectorClock* const result, i = 0; for (j = 0; j < rhs->size; j++) { - vc_check(result); - while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid) i++; if (i >= result->size) { result->size++; result->vc[i] = rhs->vc[j]; - vc_check(result); } else if (result->vc[i].threadid > rhs->vc[j].threadid) { @@ -262,7 +228,6 @@ void vc_combine(VectorClock* const result, } result->size++; result->vc[i] = rhs->vc[j]; - vc_check(result); } else { @@ -271,7 +236,6 @@ void vc_combine(VectorClock* const result, { result->vc[i].count = rhs->vc[j].count; } - vc_check(result); } } vc_check(result);