clang-tools 20.0.0git
InefficientVectorOperationCheck.h
Go to the documentation of this file.
1//===--- InefficientVectorOperationCheck.h - clang-tidy----------*- C++ -*-===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
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
11
12#include "../ClangTidyCheck.h"
13
15
16/// Finds possible inefficient `std::vector` operations (e.g. `push_back`) in
17/// for loops that may cause unnecessary memory reallocations.
18///
19/// When EnableProto, also finds calls that add element to protobuf repeated
20/// field without calling Reserve() first.
21///
22/// For the user-facing documentation see:
23/// http://clang.llvm.org/extra/clang-tidy/checks/performance/inefficient-vector-operation.html
25public:
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::performance
46
47#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Finds possible inefficient std::vector operations (e.g.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
llvm::StringMap< ClangTidyValue > OptionMap