Browse Source

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.
adaptive-webui-19844
Ivan Sorokin 10 years ago
parent
commit
5986c1dbc9
  1. 5
      src/misc.cpp

5
src/misc.cpp

@ -505,7 +505,8 @@ bool misc::isUrl(const QString &s) @@ -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) @@ -556,7 +557,7 @@ QString misc::parseHtmlLinks(const QString &raw_text)
result.replace(reURL, "\\1<a href=\"\\2\">\\2</a>");
// Capture links without scheme
QRegExp reNoScheme("<a\\s+href=\"(?!http(s?))([a-zA-Z0-9\\?%=&/_\\.-:#]+)\\s*\">");
static QRegExp reNoScheme("<a\\s+href=\"(?!http(s?))([a-zA-Z0-9\\?%=&/_\\.-:#]+)\\s*\">");
result.replace(reNoScheme, "<a href=\"http://\\1\">");
return result;

Loading…
Cancel
Save