From d19c93850278240f930e38896ed726add0a4b0fe Mon Sep 17 00:00:00 2001 From: "Daniel Von Fange (K)" Date: Mon, 18 May 2026 15:18:38 +0000 Subject: [PATCH 1/2] Cache Whiskers regexes Reuse static optimized regex objects in Whiskers template validation and rendering. On the target via-IR benchmark this regex-only variant measured 1.0335s warm average versus the 1.0640s baseline. --- libsolutil/Whiskers.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libsolutil/Whiskers.cpp b/libsolutil/Whiskers.cpp index 1f026d9464a7..239d963e4fd3 100644 --- a/libsolutil/Whiskers.cpp +++ b/libsolutil/Whiskers.cpp @@ -76,7 +76,10 @@ std::string Whiskers::render() const void Whiskers::checkTemplateValid() const { - std::regex validTemplate("<[#?!\\/]\\+{0,1}[a-zA-Z0-9_$-]+(?:[^a-zA-Z0-9_$>-]|$)"); + static std::regex const validTemplate( + "<[#?!\\/]\\+{0,1}[a-zA-Z0-9_$-]+(?:[^a-zA-Z0-9_$>-]|$)", + std::regex_constants::ECMAScript | std::regex_constants::optimize + ); std::smatch match; assertThrow( !regex_search(m_template, match, validTemplate), @@ -87,7 +90,10 @@ void Whiskers::checkTemplateValid() const void Whiskers::checkParameterValid(std::string const& _parameter) const { - static std::regex validParam("^" + paramRegex() + "$"); + static std::regex const validParam( + "^" + paramRegex() + "$", + std::regex_constants::ECMAScript | std::regex_constants::optimize + ); assertThrow( regex_match(_parameter, validParam), WhiskersError, @@ -163,7 +169,8 @@ std::string Whiskers::replace( static std::regex listOrTag( "<(" + paramRegex() + ")>|" "<#(" + paramRegex() + ")>((?:.|\\r|\\n)*?)|" - "<\\?(\\+?" + paramRegex() + ")>((?:.|\\r|\\n)*?)(((?:.|\\r|\\n)*?))?" + "<\\?(\\+?" + paramRegex() + ")>((?:.|\\r|\\n)*?)(((?:.|\\r|\\n)*?))?", + std::regex_constants::ECMAScript | std::regex_constants::optimize ); return regex_replace(_template, listOrTag, [&](std::match_results _match) -> std::string { @@ -240,4 +247,3 @@ Whiskers::StringMap Whiskers::joinMaps( ); return ret; } - From 7e003643af04df0c751c6514f5695d064e4d9f67 Mon Sep 17 00:00:00 2001 From: Daniel Von Fange Date: Mon, 18 May 2026 11:24:07 -0400 Subject: [PATCH 2/2] Keep trailing line --- libsolutil/Whiskers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libsolutil/Whiskers.cpp b/libsolutil/Whiskers.cpp index 239d963e4fd3..91c0d8af0713 100644 --- a/libsolutil/Whiskers.cpp +++ b/libsolutil/Whiskers.cpp @@ -247,3 +247,4 @@ Whiskers::StringMap Whiskers::joinMaps( ); return ret; } +