1 //===--- InefficientVectorOperationCheck.h - clang-tidy----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
12 #include "../ClangTidyCheck.h"
14 namespace clang::tidy::performance
{
16 /// Finds possible inefficient `std::vector` operations (e.g. `push_back`) in
17 /// for loops that may cause unnecessary memory reallocations.
19 /// When EnableProto, also finds calls that add element to protobuf repeated
20 /// field without calling Reserve() first.
22 /// For the user-facing documentation see:
23 /// http://clang.llvm.org/extra/clang-tidy/checks/performance/inefficient-vector-operation.html
24 class InefficientVectorOperationCheck
: public ClangTidyCheck
{
26 InefficientVectorOperationCheck(StringRef Name
, ClangTidyContext
*Context
);
27 bool isLanguageVersionSupported(const LangOptions
&LangOpts
) const override
{
28 return LangOpts
.CPlusPlus
;
30 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
31 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
32 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
35 void addMatcher(const ast_matchers::DeclarationMatcher
&TargetRecordDecl
,
36 StringRef VarDeclName
, StringRef VarDeclStmtName
,
37 const ast_matchers::DeclarationMatcher
&AppendMethodDecl
,
38 StringRef AppendCallName
, ast_matchers::MatchFinder
*Finder
);
39 const std::vector
<StringRef
> VectorLikeClasses
;
41 // If true, also check inefficient operations for proto repeated fields.
45 } // namespace clang::tidy::performance
47 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H