]> granicus.if.org Git - clang/commitdiff
Use memoization for has()-matcher.
authorDaniel Jasper <djasper@google.com>
Thu, 25 Jul 2013 09:32:14 +0000 (09:32 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 25 Jul 2013 09:32:14 +0000 (09:32 +0000)
In TUs with large classes, a matcher like

  methodDecl(ofClass(recordDecl(has(varDecl()))))

(finding all member functions of classes with static variables)
becomes unbearably slow otherwise.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187115 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ASTMatchers/ASTMatchFinder.cpp

index 9ed86177b7ff9a3310f860877c6fcb467c590c4a..5dc67e17c97eda4fdecb850b90d833fb56e5323f 100644 (file)
@@ -419,8 +419,10 @@ public:
                               BoundNodesTreeBuilder *Builder,
                               TraversalKind Traversal,
                               BindKind Bind) {
-    return matchesRecursively(Node, Matcher, Builder, 1, Traversal,
-                              Bind);
+    if (ResultCache.size() > MaxMemoizationEntries)
+      ResultCache.clear();
+    return memoizedMatchesRecursively(Node, Matcher, Builder, 1, Traversal,
+                                      Bind);
   }
   // Implements ASTMatchFinder::matchesDescendantOf.
   virtual bool matchesDescendantOf(const ast_type_traits::DynTypedNode &Node,