This commit is contained in:
gorhill 2015-09-04 16:30:53 -04:00
parent 9c88478984
commit b3d243324f
1 changed files with 33 additions and 17 deletions

View File

@ -679,32 +679,48 @@ var uBlockCollapser = (function() {
// Extract all classes: these will be passed to the cosmetic filtering // Extract all classes: these will be passed to the cosmetic filtering
// engine, and in return we will obtain only the relevant CSS selectors. // engine, and in return we will obtain only the relevant CSS selectors.
// https://github.com/gorhill/uBlock/issues/672
// http://www.w3.org/TR/2014/REC-html5-20141028/infrastructure.html#space-separated-tokens
// http://jsperf.com/enumerate-classes/6
var classesFromNodeList = function(nodes) { var classesFromNodeList = function(nodes) {
if ( !nodes || !nodes.length ) { if ( !nodes || !nodes.length ) {
return; return;
} }
var qq = queriedSelectors; var qq = queriedSelectors;
var ll = lowGenericSelectors; var ll = lowGenericSelectors;
var node, v, vv, j; var v, vv, len, c, beg, end;
var i = nodes.length; var i = nodes.length;
while ( i-- ) { while ( i-- ) {
node = nodes[i]; vv = nodes[i].className;
// http://jsperf.com/enumerate-classes if ( typeof vv !== 'string' ) { continue; }
// Chromium: classList a bit faster than manually enumerating len = vv.length;
// class names. beg = 0;
// Firefox: classList quite slower than manually enumerating for (;;) {
// class names. // Skip whitespaces
vv = node.classList; while ( beg !== len ) {
if ( typeof vv !== 'object' ) { continue; } c = vv.charCodeAt(beg);
j = vv.length || 0; if ( c !== 0x20 && (c > 0x0D || c < 0x09) ) { break; }
while ( j-- ) { beg++;
v = vv[j]; }
if ( typeof v !== 'string' ) { continue; } if ( beg === len ) { break; }
v = '.' + v; end = beg + 1;
if ( qq.hasOwnProperty(v) ) { continue; } // Skip non-whitespaces
while ( end !== len ) {
c = vv.charCodeAt(end);
if ( c === 0x20 || (c <= 0x0D && c >= 0x09) ) { break; }
end++;
}
v = '.' + vv.slice(beg, end);
if ( qq.hasOwnProperty(v) === false ) {
ll.push(v); ll.push(v);
qq[v] = true; qq[v] = true;
} }
if ( end === len ) { break; }
beg = end + 1;
}
} }
}; };