• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--- FasterStringFindCheck.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_FASTER_STRING_FIND_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTER_STRING_FIND_H
11 
12 #include "../ClangTidyCheck.h"
13 
14 #include <string>
15 #include <vector>
16 
17 namespace clang {
18 namespace tidy {
19 namespace performance {
20 
21 /// Optimize calls to std::string::find() and friends when the needle passed is
22 /// a single character string literal.
23 /// The character literal overload is more efficient.
24 ///
25 /// For the user-facing documentation see:
26 /// http://clang.llvm.org/extra/clang-tidy/checks/performance-faster-string-find.html
27 class FasterStringFindCheck : public ClangTidyCheck {
28 public:
29   FasterStringFindCheck(StringRef Name, ClangTidyContext *Context);
isLanguageVersionSupported(const LangOptions & LangOpts)30   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override{
31     return LangOpts.CPlusPlus;
32   }
33   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
36 
37 private:
38   const std::vector<std::string> StringLikeClasses;
39 };
40 
41 } // namespace performance
42 } // namespace tidy
43 } // namespace clang
44 
45 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTER_STRING_FIND_H
46