summaryrefslogtreecommitdiff
path: root/src/urlbar/urlresolver.cpp
diff options
context:
space:
mode:
authormegabigbug <megabigbug@arrakis.(none)>2010-05-16 12:32:54 +0200
committermegabigbug <megabigbug@arrakis.(none)>2010-05-16 12:32:54 +0200
commite5f4235f3dc440c7c1965204a443ce0107933d7f (patch)
tree1b3b687ebbb64c2be8082d607b6304a92bb7d1ee /src/urlbar/urlresolver.cpp
parentMerge commit 'refs/merge-requests/2262' of git://gitorious.org/rekonq/mainlin... (diff)
downloadrekonq-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/urlresolver.cpp')
-rw-r--r--src/urlbar/urlresolver.cpp48
1 files changed, 24 insertions, 24 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