Greasemonkey: optimize pattern matching a little

Moving `QUrl.toString()` out of the `_match()` function which is called
for every pattern in every stript seems to make it ~40% faster.
This commit is contained in:
Jimmy 2018-01-20 13:32:16 +13:00
parent 971b413991
commit d5d22783ea

View File

@ -196,10 +196,11 @@ class GreasemonkeyManager(QObject):
if url.scheme() not in self.greaseable_schemes: if url.scheme() not in self.greaseable_schemes:
return MatchingScripts(url, [], [], []) return MatchingScripts(url, [], [], [])
string_url = url.toString(QUrl.FullyEncoded)
def _match(pattern): def _match(pattern):
# For include and exclude rules if they start and end with '/' they # For include and exclude rules if they start and end with '/' they
# should be treated as a (ecma syntax) regular expression. # should be treated as a (ecma syntax) regular expression.
string_url = url.toString(QUrl.FullyEncoded)
if pattern.startswith('/') and pattern.endswith('/'): if pattern.startswith('/') and pattern.endswith('/'):
matches = re.search(pattern[1:-1], string_url, flags=re.I) matches = re.search(pattern[1:-1], string_url, flags=re.I)
return matches is not None return matches is not None