2022-04-24 19:13:59 +01:00
|
|
|
//===--- iwyu_regex.h - iwyu regex implementation -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef INCLUDE_WHAT_YOU_USE_IWYU_REGEX_H_
|
|
|
|
#define INCLUDE_WHAT_YOU_USE_IWYU_REGEX_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace include_what_you_use {
|
|
|
|
|
Add --regex option
As reported in issue #981, using std::regex in IWYU has caused a
tremendous performance regression for large mapping files containing
regex mappings.
$ cat t.cc
#include <string>
# with llvm::Regex
$ time include-what-you-use -Xiwyu --mapping_file=qt5_11.imp t.cc
...
real 0m0,529s
user 0m0,509s
sys 0m0,020s
# with std::regex
$ time include-what-you-use -Xiwyu --mapping_file=qt5_11.imp t.cc
...
real 0m29,870s
user 0m29,717s
sys 0m0,012s
qt5_11.imp contains 2300+ regex mappings, and <string> has a bunch of
includes, so this is a good testbed for regular expression engines, but
over 50x slower is not the result we were hoping for.
The reason we switched to std::regex was to get support for negative
lookaround (llvm::Regex does not have it), but exotic regexes in
mappings are pretty rare, and this is a significant performance hit.
Introduce a --regex option to select regex dialect, with documented
tradeoffs. Put the default back to LLVM's fast implementation.
This fixes issue #981.
2022-09-02 19:55:48 +01:00
|
|
|
enum class RegexDialect { LLVM = 0, ECMAScript = 1 };
|
|
|
|
|
|
|
|
// Parse dialect string to enum.
|
|
|
|
bool ParseRegexDialect(const char* str, RegexDialect* dialect);
|
|
|
|
|
|
|
|
// Returns true if str matches regular expression pattern for the given dialect.
|
|
|
|
bool RegexMatch(RegexDialect dialect, const std::string& str,
|
|
|
|
const std::string& pattern);
|
2022-04-24 19:13:59 +01:00
|
|
|
|
2022-10-07 15:41:07 +01:00
|
|
|
// Returns input string with the first match of pattern replaced, for the given
|
|
|
|
// regex dialect.
|
|
|
|
std::string RegexReplace(RegexDialect dialect, const std::string& str,
|
|
|
|
const std::string& pattern,
|
|
|
|
const std::string& replacement);
|
|
|
|
|
2022-04-24 19:13:59 +01:00
|
|
|
} // namespace include_what_you_use
|
|
|
|
|
|
|
|
#endif // INCLUDE_WHAT_YOU_USE_IWYU_REGEX_H_
|