From bfb33dbe91c40c083931ab3e18368058acf18e7f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 23 Feb 2009 19:15:32 +0000 Subject: [PATCH] Minor performance optimization: reduced the number of client objects that are inspected during memory deallocation. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9246 --- drd/drd_clientobj.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drd/drd_clientobj.c b/drd/drd_clientobj.c index 6c7620d8a2..bb54657033 100644 --- a/drd/drd_clientobj.c +++ b/drd/drd_clientobj.c @@ -187,6 +187,13 @@ static Bool clientobj_remove_obj(DrdClientobj* const p) return True; } +/** + * Clean up all client objects p for which their start address p->any.a1 fits + * inside the address range [ a1, a2 [. + * + * @note The implementation of this function relies on the fact that the + * data in s_clientobj_set is sorted on the start address of client objects. + */ void DRD_(clientobj_stop_using_mem)(const Addr a1, const Addr a2) { Addr removed_at; @@ -197,22 +204,17 @@ void DRD_(clientobj_stop_using_mem)(const Addr a1, const Addr a2) if (! DRD_(is_any_suppressed)(a1, a2)) return; - VG_(OSetGen_ResetIter)(s_clientobj_set); - p = VG_(OSetGen_Next)(s_clientobj_set); - for ( ; p != 0; ) + VG_(OSetGen_ResetIterAt)(s_clientobj_set, &a1); + for ( ; (p = VG_(OSetGen_Next)(s_clientobj_set)) != 0 && p->any.a1 < a2; ) { - if (a1 <= p->any.a1 && p->any.a1 < a2) - { - removed_at = p->any.a1; - clientobj_remove_obj(p); - /* The above call removes an element from the oset and hence */ - /* invalidates the iterator. Set the iterator back. */ - VG_(OSetGen_ResetIterAt)(s_clientobj_set, &removed_at); - } - else - { - p = VG_(OSetGen_Next)(s_clientobj_set); - } + tl_assert(a1 <= p->any.a1); + removed_at = p->any.a1; + clientobj_remove_obj(p); + /* + * The above call removes an element from the oset and hence + * invalidates the iterator. Restore the iterator. + */ + VG_(OSetGen_ResetIterAt)(s_clientobj_set, &removed_at); } } -- 2.47.3