summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
diff options
context:
space:
mode:
authorget <45425365+Minty-Meeo@users.noreply.github.com>2023-06-07 20:07:54 -0500
committerget <45425365+Minty-Meeo@users.noreply.github.com>2023-06-08 09:39:23 -0500
commit1df482d51fff5c91888d4c8e86831a6c605db34f (patch)
treec22ed5521c985d5742af7c53b059249376e0f399 /Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
parent44d93048b3544a3a1bd632a9b05623f67d587e1b (diff)
Prefer static const std::regex
std::regex has a relatively expensive constructor, and these are unchanging regexes.
Diffstat (limited to 'Source/Core/InputCommon/ControlReference/ExpressionParser.cpp')
-rw-r--r--Source/Core/InputCommon/ControlReference/ExpressionParser.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
index 65f9ceba4f..c93dcc5c3d 100644
--- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
+++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
@@ -102,10 +102,10 @@ std::string Lexer::FetchDelimString(char delim)
std::string Lexer::FetchWordChars()
{
- // Valid word characters:
- std::regex rx(R"([a-z\d_])", std::regex_constants::icase);
-
- return FetchCharsWhile([&rx](char c) { return std::regex_match(std::string(1, c), rx); });
+ return FetchCharsWhile([](char c) {
+ return std::isalpha(c, std::locale::classic()) || std::isdigit(c, std::locale::classic()) ||
+ c == '_';
+ });
}
Token Lexer::GetDelimitedLiteral()
@@ -134,7 +134,8 @@ Token Lexer::GetRealLiteral(char first_char)
value += first_char;
value += FetchCharsWhile([](char c) { return isdigit(c, std::locale::classic()) || ('.' == c); });
- if (std::regex_match(value, std::regex(R"(\d+(\.\d+)?)")))
+ static const std::regex re(R"(\d+(\.\d+)?)");
+ if (std::regex_match(value, re))
return Token(TOK_LITERAL, value);
return Token(TOK_INVALID);