Skip to content

Commit 2e429e7

Browse files
committed
cache regex compilation for a 20% speedup
1 parent 6732c66 commit 2e429e7

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎cpp2rust/converter/mapper.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,11 @@ std::string normalizeTranslationRule(std::string rule) {
621621
// rules.
622622
ReplaceAll(rule, "*&&", "* &&");
623623

624-
const std::array<std::pair<std::regex, std::string>, 1> normalization_rules{{
625-
// Ignore constant template parameters, i.e. replace them with _.
626-
{std::regex(R"(\b\d+\b)"), "_"},
627-
}};
624+
static const std::array<std::pair<std::regex, std::string>, 1>
625+
normalization_rules{{
626+
// Ignore constant template parameters, i.e. replace them with _.
627+
{std::regex(R"(\b\d+\b)"), "_"},
628+
}};
628629

629630
for (const auto &r : normalization_rules) {
630631
rule = std::regex_replace(rule, r.first, r.second);

0 commit comments

Comments
 (0)