[PATCH] D19877: [clang-tidy] Speedup misc-static-assert.

Samuel Benzaquen via cfe-commits cfe-commits at lists.llvm.org
Tue May 3 11:11:32 PDT 2016


sbenza created this revision.
sbenza added a reviewer: alexfh.
sbenza added a subscriber: cfe-commits.

Speedup the misc-static-assert check by not use `stmt()` as the toplevel matcher.
The framework runs a filter on the matchers before trying them on each node and
uses the toplevel type for this.
Using `stmt()` as the toplevel causes the matcher to be run on every `Stmt` node,
even if the node doesn't match the desired types.

This change speeds up clang-tidy by ~5% in a benchmark.

http://reviews.llvm.org/D19877

Files:
  clang-tidy/misc/StaticAssertCheck.cpp

Index: clang-tidy/misc/StaticAssertCheck.cpp
===================================================================
--- clang-tidy/misc/StaticAssertCheck.cpp
+++ clang-tidy/misc/StaticAssertCheck.cpp
@@ -62,11 +62,15 @@
                 hasArgument(0, AssertCondition))),
             AssertCondition);
 
-  Finder->addMatcher(stmt(anyOf(conditionalOperator(hasCondition(Condition)),
-                                ifStmt(hasCondition(Condition))),
-                          unless(isInTemplateInstantiation()))
+  Finder->addMatcher(conditionalOperator(hasCondition(Condition),
+                                         unless(isInTemplateInstantiation()))
                          .bind("condStmt"),
                      this);
+
+  Finder->addMatcher(
+      ifStmt(hasCondition(Condition), unless(isInTemplateInstantiation()))
+          .bind("condStmt"),
+      this);
 }
 
 void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19877.56028.patch
Type: text/x-patch
Size: 955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160503/ee4287dc/attachment.bin>


More information about the cfe-commits mailing list