FasterStringFindCheck.h 1.5 KB

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