From fc69b5e7aec6877cb39d5231556b35053342c01e Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Wed, 10 Jun 2026 16:12:35 +0200 Subject: [PATCH] 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 --- fairmq/Channel.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fairmq/Channel.cxx b/fairmq/Channel.cxx index b3e3207c..5fa04978 100644 --- a/fairmq/Channel.cxx +++ b/fairmq/Channel.cxx @@ -181,7 +181,8 @@ try { // validate channel name 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"; LOG(debug) << ss.str(); LOG(error) << "channel name contains illegal character: '" << m.str(0) << "', allowed characters are: a-z, A-Z, 0-9, -, _, [, ], #";