xref: /llvm-project/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h (revision 4718da506091a37ca4863d979bc541e359b79b10)
16e39e689SAlexander Kornienko //===--- InefficientAlgorithmCheck.h - clang-tidy----------------*- C++ -*-===//
26e39e689SAlexander Kornienko //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66e39e689SAlexander Kornienko //
76e39e689SAlexander Kornienko //===----------------------------------------------------------------------===//
86e39e689SAlexander Kornienko 
96e39e689SAlexander Kornienko #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTALGORITHMCHECK_H
106e39e689SAlexander Kornienko #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTALGORITHMCHECK_H
116e39e689SAlexander Kornienko 
12478fc5c8SAlexander Kornienko #include "../ClangTidyCheck.h"
136e39e689SAlexander Kornienko 
14*4718da50SCarlos Galvez namespace clang::tidy::performance {
156e39e689SAlexander Kornienko 
166e39e689SAlexander Kornienko /// Warns on inefficient use of STL algorithms on associative containers.
176e39e689SAlexander Kornienko ///
186e39e689SAlexander Kornienko /// Associative containers implements some of the algorithms as methods which
196e39e689SAlexander Kornienko /// should be preferred to the algorithms in the algorithm header. The methods
20b7ecf1c1SKazuaki Ishizaki /// can take advantage of the order of the elements.
216e39e689SAlexander Kornienko class InefficientAlgorithmCheck : public ClangTidyCheck {
226e39e689SAlexander Kornienko public:
InefficientAlgorithmCheck(StringRef Name,ClangTidyContext * Context)236e39e689SAlexander Kornienko   InefficientAlgorithmCheck(StringRef Name, ClangTidyContext *Context)
246e39e689SAlexander Kornienko       : ClangTidyCheck(Name, Context) {}
isLanguageVersionSupported(const LangOptions & LangOpts)25e40a742aSNathan James   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
26e40a742aSNathan James     return LangOpts.CPlusPlus;
27e40a742aSNathan James   }
286e39e689SAlexander Kornienko   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
296e39e689SAlexander Kornienko   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
getCheckTraversalKind()30b0de3630SFangrui Song   std::optional<TraversalKind> getCheckTraversalKind() const override {
316c2eca96SStephen Kelly     return TK_IgnoreUnlessSpelledInSource;
326c2eca96SStephen Kelly   }
336e39e689SAlexander Kornienko };
346e39e689SAlexander Kornienko 
35*4718da50SCarlos Galvez } // namespace clang::tidy::performance
366e39e689SAlexander Kornienko 
376e39e689SAlexander Kornienko #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTALGORITHMCHECK_H
38