mirror of https://github.com/gorhill/uBlock.git
Avoid using Element.classList in DOM surveyor
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/discussions/2076
This commit is contained in:
parent
3d6aead585
commit
1423330703
|
@ -1024,7 +1024,6 @@ vAPI.DOMFilterer = class {
|
||||||
// Extract all classes/ids: these will be passed to the cosmetic
|
// Extract all classes/ids: these will be passed to the cosmetic
|
||||||
// filtering engine, and in return we will obtain only the relevant
|
// filtering engine, and in return we will obtain only the relevant
|
||||||
// CSS selectors.
|
// CSS selectors.
|
||||||
const reWhitespace = /\s/;
|
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/672
|
// https://github.com/gorhill/uBlock/issues/672
|
||||||
// http://www.w3.org/TR/2014/REC-html5-20141028/infrastructure.html#space-separated-tokens
|
// http://www.w3.org/TR/2014/REC-html5-20141028/infrastructure.html#space-separated-tokens
|
||||||
|
@ -1039,19 +1038,21 @@ vAPI.DOMFilterer = class {
|
||||||
queriedIds.add(s);
|
queriedIds.add(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/discussions/2076
|
||||||
|
// Performance: avoid using Element.classList
|
||||||
const classesFromNode = (node, out) => {
|
const classesFromNode = (node, out) => {
|
||||||
const s = node.className;
|
const s = node.getAttribute('class');
|
||||||
if ( typeof s !== 'string' || s.length === 0 ) { return; }
|
if ( typeof s !== 'string' ) { return; }
|
||||||
if ( reWhitespace.test(s) === false ) {
|
const len = s.length;
|
||||||
if ( queriedClasses.has(s) ) { return; }
|
for ( let beg = 0, end = 0, token = ''; beg < len; beg += 1 ) {
|
||||||
out.push(s);
|
end = s.indexOf(' ', beg);
|
||||||
queriedClasses.add(s);
|
if ( end === beg ) { continue; }
|
||||||
return;
|
if ( end === -1 ) { end = len; }
|
||||||
}
|
token = s.slice(beg, end);
|
||||||
for ( const s of node.classList.values() ) {
|
beg = end;
|
||||||
if ( queriedClasses.has(s) ) { continue; }
|
if ( queriedClasses.has(token) ) { continue; }
|
||||||
out.push(s);
|
out.push(token);
|
||||||
queriedClasses.add(s);
|
queriedClasses.add(token);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue