Index: lib/matcher.js
===================================================================
--- a/lib/matcher.js
+++ b/lib/matcher.js
@@ -417,16 +417,61 @@
         result = candidate;
         resultCount = count;
         resultLength = candidate.length;
       }
     }
     return result;
   }
 
+  _matchFilterWithoutDomain(filter, location, typeMask, thirdParty, sitekey,
+                            collection)
+  {
+    if (filter.matchesWithoutDomain(location, typeMask, thirdParty, sitekey))
+    {
+      if (!collection)
+        return filter;
+
+      collection.push(filter);
+    }
+
+    return null;
+  }
+
+  _matchFiltersByDomain(filtersByDomain, location, typeMask, docDomain,
+                        thirdParty, sitekey, specificOnly, collection)
+  {
+    let excluded = new Set();
+
+    for (let suffix of domainSuffixes(docDomain ?
+                                        normalizeHostname(docDomain) : "",
+                                      !specificOnly))
+    {
+      let filters = filtersByDomain.get(suffix);
+      if (filters)
+      {
+        for (let [filter, include] of filters.entries())
+        {
+          if (!include)
+          {
+            excluded.add(filter);
+          }
+          else if ((excluded.size == 0 || !excluded.has(filter)) &&
+                   filter.matchesWithoutDomain(location, typeMask, thirdParty,
+                                               sitekey, collection))
+          {
+            return filter;
+          }
+        }
+      }
+    }
+
+    return null;
+  }
+
   _checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty,
                          sitekey, specificOnly, collection)
   {
     let filters = this._simpleFiltersByKeyword.get(keyword);
     if (filters)
     {
       let lowerCaseLocation = location.toLowerCase();
 
@@ -479,59 +524,28 @@
   }
 
   _checkEntryMatchByDomain(keyword, location, typeMask, docDomain, thirdParty,
                            sitekey, specificOnly, collection)
   {
     let filtersByDomain = this._filterDomainMapsByKeyword.get(keyword);
     if (filtersByDomain)
     {
-      // Because of the memory optimization in the add function, most of the
-      // time this will be a filter rather than a map.
-      if (!(filtersByDomain instanceof Map))
+      if (filtersByDomain instanceof Map)
       {
-        if (filtersByDomain.matchesWithoutDomain(location, typeMask,
-                                                 thirdParty, sitekey))
-        {
-          if (!collection)
-            return filtersByDomain;
-
-          collection.push(filtersByDomain);
-        }
-
-        return null;
+        return this._matchFiltersByDomain(filtersByDomain, location, typeMask,
+                                          docDomain, thirdParty, sitekey,
+                                          specificOnly, collection);
       }
 
-      let excluded = new Set();
-
-      for (let suffix of domainSuffixes(docDomain ?
-                                          normalizeHostname(docDomain) : "",
-                                        !specificOnly))
-      {
-        let filters = filtersByDomain.get(suffix);
-        if (filters)
-        {
-          for (let [filter, include] of filters.entries())
-          {
-            if (!include)
-            {
-              excluded.add(filter);
-            }
-            else if ((excluded.size == 0 || !excluded.has(filter)) &&
-                     filter.matchesWithoutDomain(location, typeMask,
-                                                 thirdParty, sitekey))
-            {
-              if (!collection)
-                return filter;
-
-              collection.push(filter);
-            }
-          }
-        }
-      }
+      // Because of the memory optimization in the add function, most of the
+      // time this will be a filter rather than a map.
+      return this._matchFilterWithoutDomain(filtersByDomain, location,
+                                            typeMask, thirdParty, sitekey,
+                                            collection);
     }
 
     return null;
   }
 
   /**
    * Checks whether the entries for a particular keyword match a URL
    * @param {string} keyword
