]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Small optimisation in helgrind address description
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 4 Nov 2017 07:32:03 +0000 (08:32 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 4 Nov 2017 07:32:03 +0000 (08:32 +0100)
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).

helgrind/hg_main.c

index 0f8c946743e73871b79a9ab114cf720d82c268c4..95945f36bbfe9d9e35435bb46104ae11aa4298f0 100644 (file)
@@ -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