blob: 71a45705f1e81d776564131154b9b3474eb9583e [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===--- 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
17namespace clang {
18namespace tidy {
19namespace 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
27class FasterStringFindCheck : public ClangTidyCheck {
28public:
29 FasterStringFindCheck(StringRef Name, ClangTidyContext *Context);
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
37private:
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