From: Philippe Waroquiers Date: Sat, 4 Nov 2017 07:32:03 +0000 (+0100) Subject: Small optimisation in helgrind address description X-Git-Tag: VALGRIND_3_14_0~209 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1eb5ea2afed92e38a15159cdef559785166a02a9;p=thirdparty%2Fvalgrind.git Small optimisation in helgrind address description Searching if an addr is in a malloc-ed client block is expensive (linear search) So, before scanning the list of malloc block, check that the address is in a client heap segment : this is a fast operation (it has a small cache, and for cache miss, does a dichotomic search) and avoids scanning a often big list (for big applications). --- diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index 0f8c946743..95945f36bb 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -4385,6 +4385,12 @@ Bool HG_(mm_find_containing_block)( /*OUT*/ExeContext** where, Int i; const Int n_fast_check_words = 16; + /* Before searching the list of allocated blocks in hg_mallocmeta_table, + first verify that data_addr is in a heap client segment. */ + const NSegment *s = VG_(am_find_nsegment) (data_addr); + if (s == NULL || !s->isCH) + return False; + /* First, do a few fast searches on the basis that data_addr might be exactly the start of a block or up to 15 words inside. This can happen commonly via the creq