diff options
author | megabigbug <megabigbug@arrakis.(none)> | 2010-05-16 12:32:54 +0200 |
---|---|---|
committer | megabigbug <megabigbug@arrakis.(none)> | 2010-05-16 12:32:54 +0200 |
commit | e5f4235f3dc440c7c1965204a443ce0107933d7f (patch) | |
tree | 1b3b687ebbb64c2be8082d607b6304a92bb7d1ee /src/urlbar | |
parent | Merge commit 'refs/merge-requests/2262' of git://gitorious.org/rekonq/mainlin... (diff) | |
download | rekonq-e5f4235f3dc440c7c1965204a443ce0107933d7f.tar.xz |
performance improvement: build one static regexp instead of several in the isHttp method (they was built for each key pressed)
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/urlresolver.cpp | 48 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 2 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 840fd78f..1376ca2c 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -60,9 +60,32 @@ bool UrlSearchItem::operator==(const UrlSearchItem &i) const } +QRegExp* UrlResolver::_browseRegexp = NULL; + + UrlResolver::UrlResolver(const QString &typedUrl) : _typedString(typedUrl.trimmed()) { + if (_browseRegexp==NULL) + { + QString protocol = "^(http://|https://|file://|ftp://)"; + + QString ipv4 = "^0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"\ + "\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"; + + QString ipv6 = "^([0-9a-fA-F]{4}|0)(\\:([0-9a-fA-F]{4}|0)){7}"; + + QString address = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ + "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ + "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ + "m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|"\ + "s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|"\ + "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ + "pro)"; + + _browseRegexp = new QRegExp("(" + protocol + ")|(" + address + ")|(" + ipv6 + ")|(" + ipv4 +")"); + } + } @@ -76,7 +99,7 @@ UrlSearchList UrlResolver::orderedSearchItems() UrlSearchList list; - if(isHttp()) + if(_browseRegexp->indexIn(_typedString) != -1) { list << qurlFromUserInputResolution(); list << webSearchesResolution(); @@ -135,29 +158,6 @@ UrlSearchList UrlResolver::orderedSearchItems() } -bool UrlResolver::isHttp() -{ - QString ipv4 = "^0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"\ - "\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"; - - QString ipv6 = "^([0-9a-fA-F]{4}|0)(\\:([0-9a-fA-F]{4}|0)){7}"; - - QString address = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ - "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ - "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ - "m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|"\ - "s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|"\ - "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ - "pro)"; - - return _typedString.startsWith( QL1S("http://") ) - || _typedString.startsWith( QL1S("https://") ) - || (QRegExp(address, Qt::CaseInsensitive).indexIn(_typedString) != -1) - || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_typedString) != -1) - || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_typedString) != -1); -} - - ////////////////////////////////////////////////////////////////////////// // PRIVATE ENGINES diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 7a8262b3..7d3db967 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -84,7 +84,7 @@ private: UrlSearchList bookmarksResolution(); UrlSearchList placeTypedDomaineNameOnTop(UrlSearchList list); - bool isHttp(); + static QRegExp *_browseRegexp; }; #endif // URL_RESOLVER_H |