From 5986c1dbc9fca180ed089646719f962f3aa28402 Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Sun, 9 Nov 2014 12:51:30 +0300 Subject: [PATCH] Cache QRegExp in misc::parseHtmlLinks() This commit should improve performance when user navigating through torrent list using up/down keys. A scrolling through all the list (276 torrents) took: Total wall time: 18.813s Total CPU time: 3.210s misc::parseHtmlLinks(): 0.096s misc::parseHtmlLinks() is 8th most hottest function on this use case. --- src/misc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 3f2fa27aa..1504d89db 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -505,7 +505,8 @@ bool misc::isUrl(const QString &s) QString misc::parseHtmlLinks(const QString &raw_text) { QString result = raw_text; - QRegExp reURL("(\\s|^)" //start with whitespace or beginning of line + static QRegExp reURL( + "(\\s|^)" //start with whitespace or beginning of line "(" "(" //case 1 -- URL with scheme "(http(s?))\\://" //start with scheme @@ -556,7 +557,7 @@ QString misc::parseHtmlLinks(const QString &raw_text) result.replace(reURL, "\\1\\2"); // Capture links without scheme - QRegExp reNoScheme(""); + static QRegExp reNoScheme(""); result.replace(reNoScheme, ""); return result;