r187115 - Use memoization for has()-matcher.

Daniel Jasper djasper at google.com
Thu Jul 25 02:32:15 PDT 2013


Author: djasper
Date: Thu Jul 25 04:32:14 2013
New Revision: 187115

URL: http://llvm.org/viewvc/llvm-project?rev=187115&view=rev
Log:
Use memoization for has()-matcher.

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.

Modified:
    cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp?rev=187115&r1=187114&r2=187115&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp Thu Jul 25 04:32:14 2013
@@ -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,





More information about the cfe-commits mailing list