From 1df482d51fff5c91888d4c8e86831a6c605db34f Mon Sep 17 00:00:00 2001 From: get <45425365+Minty-Meeo@users.noreply.github.com> Date: Wed, 7 Jun 2023 20:07:54 -0500 Subject: Prefer static const std::regex std::regex has a relatively expensive constructor, and these are unchanging regexes. --- Source/Core/InputCommon/ControlReference/ExpressionParser.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Source/Core/InputCommon/ControlReference/ExpressionParser.cpp') 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); -- cgit v1.2.3