Skip to content

Commit 4b24274

Browse files
committed
Make all std::regex instances static
Per [1] we really shouldn't be using regex. In the cases we do, it's a HUUUUUGE performance benefit to be compiling the regex ONCE. The only downside is a slight increase in memory usage. [1]: #176 Signed-off-by: Ed Tanous <[email protected]> Change-Id: I8644b8a07810349fb60bfa0258a13e815912a38e
1 parent 283860f commit 4b24274

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

include/dbus_monitor.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ inline void requestRoutes(App& app)
173173

174174
// These regexes derived on the rules here:
175175
// https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
176-
std::regex validPath("^/([A-Za-z0-9_]+/?)*$");
177-
std::regex validInterface(
176+
static std::regex validPath("^/([A-Za-z0-9_]+/?)*$");
177+
static std::regex validInterface(
178178
"^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)+$");
179179

180180
for (const auto& thisPath : *paths)

include/dbus_utility.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ using MapperEndPoints = std::vector<std::string>;
103103

104104
inline void escapePathForDbus(std::string& path)
105105
{
106-
const std::regex reg("[^A-Za-z0-9_/]");
106+
const static std::regex reg("[^A-Za-z0-9_/]");
107107
std::regex_replace(path.begin(), path.begin(), path.end(), reg, "_");
108108
}
109109

include/openbmc_dbus_rest.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const constexpr char* forbiddenResDesc =
101101

102102
inline bool validateFilename(const std::string& filename)
103103
{
104-
std::regex validFilename(R"(^[\w\- ]+(\.?[\w\- ]*)$)");
104+
static std::regex validFilename(R"(^[\w\- ]+(\.?[\w\- ]*)$)");
105105

106106
return std::regex_match(filename, validFilename);
107107
}
@@ -2562,7 +2562,7 @@ inline void requestRoutes(App& app)
25622562
// Filename should be in alphanumeric, dot and underscore
25632563
// Its based on phosphor-debug-collector application
25642564
// dumpfile format
2565-
std::regex dumpFileRegex("[a-zA-Z0-9\\._]+");
2565+
static std::regex dumpFileRegex("[a-zA-Z0-9\\._]+");
25662566
if (!std::regex_match(dumpFileName, dumpFileRegex))
25672567
{
25682568
BMCWEB_LOG_ERROR << "Invalid dump filename " << dumpFileName;

redfish-core/lib/ethernet.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ inline bool isHostnameValid(const std::string& hostname)
949949
// MUST handle host names of up to 63 characters (RFC 1123)
950950
// labels cannot start or end with hyphens (RFC 952)
951951
// labels can start with numbers (RFC 1123)
952-
const std::regex pattern(
952+
const static std::regex pattern(
953953
"^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$");
954954

955955
return std::regex_match(hostname, pattern);
@@ -959,7 +959,7 @@ inline bool isDomainnameValid(const std::string& domainname)
959959
{
960960
// Can have multiple subdomains
961961
// Top Level Domain's min length is 2 character
962-
const std::regex pattern(
962+
const static std::regex pattern(
963963
"^([A-Za-z0-9][a-zA-Z0-9\\-]{1,61}|[a-zA-Z0-9]{1,30}\\.)*[a-zA-Z]{2,}$");
964964

965965
return std::regex_match(domainname, pattern);

0 commit comments

Comments
 (0)