]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Improve suppression matching performance when fun or obj is a simple string
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 26 Jul 2012 21:37:36 +0000 (21:37 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 26 Jul 2012 21:37:36 +0000 (21:37 +0000)
Idea is from Julian, possible bugs are mine.

If the fun or obj is a simple string and not a patter (so no *, no ?),
use a simple string comparison rather than a call to a wildcard matching.

On a leak search with a lot of reachable loss records and a lot of suppr,
it improves the speed of the leak search by 10 to 15%.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12789

coregrind/m_errormgr.c

index 44976a804b18e31ae1a0e8a0713b5b6d7023d952..22f9a6e0dffbb648f03c5aa87bac326a12f0d6d8 100644 (file)
@@ -211,6 +211,8 @@ typedef
 typedef
    struct {
       SuppLocTy ty;
+      Bool      name_is_simple_str; /* True if name is a string without
+                                       '?' and '*' wildcard characters. */
       Char*     name; /* NULL for NoName and DotDotDot */
    }
    SuppLoc;
@@ -1103,6 +1105,18 @@ Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp, Int* lineno )
 }
 
 
+/* True if s contains no wildcard (?, *) characters. */
+static Bool is_simple_str (Char *s)
+{
+   int i;
+   while (*s) {
+      if (*s == '?' || *s == '*')
+         return False;
+      s++;
+   }
+   return True;
+}
+
 /* buf contains the raw name of a caller, supposedly either
        fun:some_function_name   or
        obj:some_object_name     or
@@ -1117,17 +1131,20 @@ static Bool setLocationTy ( SuppLoc* p, Char *buf )
    if (VG_(strncmp)(buf, "fun:", 4) == 0) {
       p->name = VG_(arena_strdup)(VG_AR_CORE,
                                   "errormgr.sLTy.1", buf+4);
+      p->name_is_simple_str = is_simple_str (p->name);
       p->ty = FunName;
       return True;
    }
    if (VG_(strncmp)(buf, "obj:", 4) == 0) {
       p->name = VG_(arena_strdup)(VG_AR_CORE,
                                   "errormgr.sLTy.2", buf+4);
+      p->name_is_simple_str = is_simple_str (p->name);
       p->ty = ObjName;
       return True;
    }
    if (VG_(strcmp)(buf, "...") == 0) {
       p->name = NULL;
+      p->name_is_simple_str = False;
       p->ty = DotDotDot;
       return True;
    }
@@ -1198,6 +1215,7 @@ static void load_one_suppressions_file ( Char* filename )
       // Initialise temporary reading-in buffer.
       for (i = 0; i < VG_MAX_SUPP_CALLERS; i++) {
          tmp_callers[i].ty   = NoName;
+         tmp_callers[i].name_is_simple_str = False;
          tmp_callers[i].name = NULL;
       }
 
@@ -1425,8 +1443,11 @@ static Bool supp_pattEQinp ( void* supplocV, void* addrV )
    /* So now we have the function or object name in caller_name, and
       the pattern (at the character level) to match against is in
       supploc->name.  Hence (and leading to a re-entrant call of
-      VG_(generic_match)): */
-   return VG_(string_match)(supploc->name, caller_name);
+      VG_(generic_match) if there is a wildcard character): */
+   if (supploc->name_is_simple_str)
+      return VG_(strcmp) (supploc->name, caller_name) == 0;
+   else
+      return VG_(string_match)(supploc->name, caller_name);
 }
 
 /////////////////////////////////////////////////////