]> spindle.queued.net Git - midori/commitdiff
Speedup adblock by removing greedy regex if we have 1 or 2 signatures
authorAlexander Butenko <a.butenka@gmail.com>
Thu, 14 Jan 2010 00:52:43 +0000 (01:52 +0100)
committerChristian Dywan <christian@twotoasts.de>
Thu, 14 Jan 2010 00:52:43 +0000 (01:52 +0100)
extensions/adblock.c

index 26ec53781aba72369723daa1ec6647be19ed90c6..042cfde3df74495b1f3e80873183bc0b9fa4b7ea 100644 (file)
@@ -926,6 +926,7 @@ adblock_compile_regexp (GHashTable* tbl,
     if (!g_regex_match_simple ("^/.*[\\^\\$\\*].*/$", patt, G_REGEX_UNGREEDY, G_REGEX_MATCH_NOTEMPTY))
     {
         int len = strlen (patt);
+        int signature_count = 0;
         for (pos = len - SIGNATURE_SIZE; pos >= 0; pos--) {
             sig = g_strndup (patt + pos, SIGNATURE_SIZE);
             if (!g_regex_match_simple ("[\\*]", sig, G_REGEX_UNGREEDY, G_REGEX_MATCH_NOTEMPTY) &&
@@ -933,6 +934,7 @@ adblock_compile_regexp (GHashTable* tbl,
             {
                 /* g_debug ("sig: %s %s", sig, patt); */
                 g_hash_table_insert (keystbl, sig, regex);
+                signature_count++;
             }
             else
             {
@@ -945,6 +947,8 @@ adblock_compile_regexp (GHashTable* tbl,
                 g_free (sig);
             }
         }
+        if (signature_count > 1 && g_hash_table_lookup (tbl, opts))
+            g_hash_table_steal (tbl, opts);
     }
     else
     {