refactor: compile channel name validation regex only once

- the pattern is constant; compiling it on every Validate() call is
  wasted work and, when channels are validated from multiple threads,
  needlessly exercises libstdc++'s lazily-populated ctype caches
This commit is contained in:
Dennis Klein
2026-06-10 16:12:35 +02:00
committed by Dennis Klein
parent 19e607e486
commit fc69b5e7ae

View File

@@ -181,7 +181,8 @@ try {
// validate channel name // validate channel name
smatch m; smatch m;
if (regex_search(fName, m, regex(R"([^a-zA-Z0-9\-_\[\]#])"))) { static regex const invalidName(R"([^a-zA-Z0-9\-_\[\]#])");
if (regex_search(fName, m, invalidName)) {
ss << "INVALID"; ss << "INVALID";
LOG(debug) << ss.str(); LOG(debug) << ss.str();
LOG(error) << "channel name contains illegal character: '" << m.str(0) << "', allowed characters are: a-z, A-Z, 0-9, -, _, [, ], #"; LOG(error) << "channel name contains illegal character: '" << m.str(0) << "', allowed characters are: a-z, A-Z, 0-9, -, _, [, ], #";