Index: trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java	(revision 15891)
+++ trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java	(revision 15893)
@@ -1971,17 +1971,34 @@
         try {
             final List<Selector> selectors = new MapCSSParser(new StringReader(mapCSS)).selectors_for_search();
-            return new Match() {
-                @Override
-                public boolean match(OsmPrimitive osm) {
-                    for (Selector selector : selectors) {
-                        if (selector.matches(new Environment(osm))) {
-                            return true;
-                        }
-                    }
-                    return false;
-                }
-            };
+            return new MapCSSMatch(selectors);
         } catch (ParseException | IllegalArgumentException e) {
             throw new SearchParseError(tr("Failed to parse MapCSS selector"), e);
+        }
+    }
+
+    private static class MapCSSMatch extends Match {
+        private final List<Selector> selectors;
+
+        MapCSSMatch(List<Selector> selectors) {
+            this.selectors = selectors;
+        }
+
+        @Override
+        public boolean match(OsmPrimitive osm) {
+            return selectors.stream()
+                    .anyMatch(selector -> selector.matches(new Environment(osm)));
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+            MapCSSMatch that = (MapCSSMatch) o;
+            return Objects.equals(selectors, that.selectors);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(selectors);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java	(revision 15891)
+++ trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java	(revision 15893)
@@ -159,10 +159,34 @@
         @Override
         public SearchCompiler.Match get() {
-            return new SearchCompiler.Match() {
-                @Override
-                public boolean match(OsmPrimitive osm) {
-                    return rule.getTagValuesForPrimitive(osm).anyMatch(v -> v == value);
-                }
-            };
+            return new Match(rule, value);
+        }
+    }
+
+    static class Match extends SearchCompiler.Match {
+        final AutoFilterRule rule;
+        final int value;
+
+        Match(AutoFilterRule rule, int value) {
+            this.rule = rule;
+            this.value = value;
+        }
+
+        @Override
+        public boolean match(OsmPrimitive osm) {
+            return rule.getTagValuesForPrimitive(osm).anyMatch(v -> v == value);
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+            Match match = (Match) o;
+            return value == match.value &&
+                    Objects.equals(rule, match.rule);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(rule, value);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterRule.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterRule.java	(revision 15891)
+++ trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterRule.java	(revision 15893)
@@ -192,4 +192,17 @@
 
     @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        AutoFilterRule that = (AutoFilterRule) o;
+        return Objects.equals(key, that.key);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(key);
+    }
+
+    @Override
     public String toString() {
         return key + '[' + minZoomLevel + ']';
