brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 5f3b88f Raw
48 lines · c
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTVECTOROPERATIONCHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTVECTOROPERATIONCHECK_H11 12#include "../ClangTidyCheck.h"13 14namespace clang::tidy::performance {15 16/// Finds possible inefficient `std::vector` operations (e.g. `push_back`) in17/// for loops that may cause unnecessary memory reallocations.18///19/// When EnableProto, also finds calls that add element to protobuf repeated20/// field without calling Reserve() first.21///22/// For the user-facing documentation see:23/// https://clang.llvm.org/extra/clang-tidy/checks/performance/inefficient-vector-operation.html24class InefficientVectorOperationCheck : public ClangTidyCheck {25public:26  InefficientVectorOperationCheck(StringRef Name, ClangTidyContext *Context);27  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {28    return LangOpts.CPlusPlus;29  }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;33 34private: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;40 41  // If true, also check inefficient operations for proto repeated fields.42  bool EnableProto;43};44 45} // namespace clang::tidy::performance46 47#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTVECTOROPERATIONCHECK_H48