AIconLabel: make regex static and initialize label_contains_icon

Compile the icon-extraction std::regex objects once via static locals
instead of rebuilding them on every update() of every AIconLabel-derived
module (custom, mpris, ...). Also default-initialize label_contains_icon
to false at its declaration.
This commit is contained in:
Alex
2026-07-03 22:10:16 +02:00
parent 31dfd44f0b
commit c5cefb5520
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ class AIconLabel : public ALabel {
Gtk::Box box_; Gtk::Box box_;
unsigned app_icon_size_{24}; unsigned app_icon_size_{24};
bool label_contains_icon; bool label_contains_icon{false};
bool iconEnabled() const; bool iconEnabled() const;
}; };
+2 -2
View File
@@ -65,12 +65,12 @@ std::tuple<std::string, std::string> AIconLabel::extractIcon(const std::string&
std::string icon_result = ""; std::string icon_result = "";
std::string label_result = input; std::string label_result = input;
try { try {
const std::regex icon_search(R"((?=\\0icon\\1f).+?(?=\\n))"); static const std::regex icon_search(R"((?=\\0icon\\1f).+?(?=\\n))");
std::smatch icon_match; std::smatch icon_match;
if (std::regex_search(input, icon_match, icon_search)) { if (std::regex_search(input, icon_match, icon_search)) {
icon_result = icon_match[0].str().substr(9); icon_result = icon_match[0].str().substr(9);
const std::regex clean_label_pattern(R"(\\0icon\\1f.+?\\n)"); static const std::regex clean_label_pattern(R"(\\0icon\\1f.+?\\n)");
label_result = std::regex_replace(input, clean_label_pattern, ""); label_result = std::regex_replace(input, clean_label_pattern, "");
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {