Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial types
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 29 May 2015 19:42:19 +0000 (19:42 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 29 May 2015 19:42:19 +0000 (19:42 +0000)
commit3204b152b53e539304f9da2aff100876aeefa856
tree413a942366f5a46724c5658daf847ee3493e9f5e
parent36cbc0901f7a8ac02511143f1b5e4b6478221239
Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial types

If the type isn't trivially moveable emplace can skip a potentially
expensive move. It also saves a couple of characters.

Call sites were found with the ASTMatcher + some semi-automated cleanup.

memberCallExpr(
    argumentCountIs(1), callee(methodDecl(hasName("push_back"))),
    on(hasType(recordDecl(has(namedDecl(hasName("emplace_back")))))),
    hasArgument(0, bindTemporaryExpr(
                       hasType(recordDecl(hasNonTrivialDestructor())),
                       has(constructExpr()))),
    unless(isInTemplateInstantiation()))

No functional change intended.

llvm-svn: 238601
30 files changed:
clang/include/clang/Lex/HeaderSearchOptions.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Lex/PreprocessorOptions.h
clang/lib/ARCMigrate/ObjCMT.cpp
clang/lib/AST/Stmt.cpp
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
clang/lib/Basic/Diagnostic.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/Tools.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitHeaderSearch.cpp
clang/lib/Frontend/TextDiagnosticBuffer.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
clang/lib/Tooling/CompilationDatabase.cpp
clang/lib/Tooling/JSONCompilationDatabase.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/utils/TableGen/ClangCommentCommandInfoEmitter.cpp
clang/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp
clang/utils/TableGen/NeonEmitter.cpp