Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:21

0001 //===--- InefficientVectorOperationCheck.h - clang-tidy----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 
0014 namespace clang::tidy::performance {
0015 
0016 /// Finds possible inefficient `std::vector` operations (e.g. `push_back`) in
0017 /// for loops that may cause unnecessary memory reallocations.
0018 ///
0019 /// When EnableProto, also finds calls that add element to protobuf repeated
0020 /// field without calling Reserve() first.
0021 ///
0022 /// For the user-facing documentation see:
0023 /// http://clang.llvm.org/extra/clang-tidy/checks/performance/inefficient-vector-operation.html
0024 class InefficientVectorOperationCheck : public ClangTidyCheck {
0025 public:
0026   InefficientVectorOperationCheck(StringRef Name, ClangTidyContext *Context);
0027   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override{
0028     return LangOpts.CPlusPlus;
0029   }
0030   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0031   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0032   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0033 
0034 private:
0035   void addMatcher(const ast_matchers::DeclarationMatcher &TargetRecordDecl,
0036                   StringRef VarDeclName, StringRef VarDeclStmtName,
0037                   const ast_matchers::DeclarationMatcher &AppendMethodDecl,
0038                   StringRef AppendCallName, ast_matchers::MatchFinder *Finder);
0039   const std::vector<StringRef> VectorLikeClasses;
0040 
0041   // If true, also check inefficient operations for proto repeated fields.
0042   bool EnableProto;
0043 };
0044 
0045 } // namespace clang::tidy::performance
0046 
0047 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H