mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 17:41:03 +01:00
code review: use regex to speed up CSS selector validation
This commit is contained in:
parent
f55144a179
commit
c1d3b6222e
1 changed files with 5 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
uBlock Origin - a browser extension to block requests.
|
uBlock Origin - a browser extension to block requests.
|
||||||
Copyright (C) 2017 Raymond Hill
|
Copyright (C) 2017-2018 Raymond Hill
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -94,7 +94,11 @@
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
matchesFn = div.querySelector.bind(div);
|
matchesFn = div.querySelector.bind(div);
|
||||||
}
|
}
|
||||||
|
// Quick regex-based validation -- most cosmetic filters are of the
|
||||||
|
// simple form and in such case a regex is much faster.
|
||||||
|
var reSimple = /^[#.][\w-]+$/;
|
||||||
return function(s) {
|
return function(s) {
|
||||||
|
if ( reSimple.test(s) ) { return true; }
|
||||||
try {
|
try {
|
||||||
matchesFn(s + ', ' + s + ':not(#foo)');
|
matchesFn(s + ', ' + s + ':not(#foo)');
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
|
Loading…
Reference in a new issue