From: Benjamin Kramer Date: Fri, 29 Aug 2014 11:22:47 +0000 (+0000) Subject: ASTMatchers: Replace some copies of the bound nodes tree builder with moves. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10a6347d4b69284dccbb036dbd00ebb2c8d54448;p=clang ASTMatchers: Replace some copies of the bound nodes tree builder with moves. But don't move if all we do is clearing the thing. The move method is too large to be inlined and performs a ton of unnecessary checking when the RHS is empty. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216723 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 7063606b59..9dd6f49eba 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -2285,7 +2285,7 @@ AST_POLYMORPHIC_MATCHER_P(hasAnyArgument, AST_POLYMORPHIC_SUPPORTED_TYPES_2( BoundNodesTreeBuilder Result(*Builder); if (InnerMatcher.matches(*Node.getArg(I)->IgnoreParenImpCasts(), Finder, &Result)) { - *Builder = Result; + *Builder = std::move(Result); return true; } } @@ -3614,7 +3614,7 @@ AST_MATCHER_P(SwitchStmt, forEachSwitchCase, internal::Matcher, Result.addMatch(CaseBuilder); } } - *Builder = Result; + *Builder = std::move(Result); return Matched; } @@ -3637,7 +3637,7 @@ AST_MATCHER_P(CXXConstructorDecl, forEachConstructorInitializer, Result.addMatch(InitBuilder); } } - *Builder = Result; + *Builder = std::move(Result); return Matched; } diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index 80a3632bdf..7eacf23b44 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -262,7 +262,7 @@ public: // Delete all bindings when a matcher does not match. // This prevents unexpected exposure of bound nodes in unmatches // branches of the match tree. - *Builder = BoundNodesTreeBuilder(); + Builder->removeBindings([](const BoundNodesMap &) { return true; }); return false; } @@ -490,7 +490,7 @@ bool matchesFirstInRange(const MatcherT &Matcher, IteratorT Start, for (IteratorT I = Start; I != End; ++I) { BoundNodesTreeBuilder Result(*Builder); if (Matcher.matches(*I, Finder, &Result)) { - *Builder = Result; + *Builder = std::move(Result); return true; } } @@ -506,7 +506,7 @@ bool matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start, for (IteratorT I = Start; I != End; ++I) { BoundNodesTreeBuilder Result(*Builder); if (Matcher.matches(**I, Finder, &Result)) { - *Builder = Result; + *Builder = std::move(Result); return true; } } diff --git a/lib/ASTMatchers/ASTMatchersInternal.cpp b/lib/ASTMatchers/ASTMatchersInternal.cpp index 47b8b6d2f2..e501ee64f7 100644 --- a/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -81,7 +81,7 @@ bool EachOfVariadicOperator(const ast_type_traits::DynTypedNode DynNode, Result.addMatch(BuilderInner); } } - *Builder = Result; + *Builder = std::move(Result); return Matched; } @@ -92,7 +92,7 @@ bool AnyOfVariadicOperator(const ast_type_traits::DynTypedNode DynNode, for (size_t i = 0, e = InnerMatchers.size(); i != e; ++i) { BoundNodesTreeBuilder Result = *Builder; if (InnerMatchers[i].matches(DynNode, Finder, &Result)) { - *Builder = Result; + *Builder = std::move(Result); return true; } }