mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-06 19:02:30 +01:00
code review: marginal performance improvement
This commit is contained in:
parent
1e1508cdd2
commit
28084e1dc9
@ -1,7 +1,7 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
uBlock Origin - a browser extension to block requests.
|
uBlock Origin - a browser extension to block requests.
|
||||||
Copyright (C) 2014-2016 Raymond Hill
|
Copyright (C) 2014-2017 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
|
||||||
@ -1533,36 +1533,48 @@ vAPI.domSurveyor = (function() {
|
|||||||
|
|
||||||
var surveyPhase1 = function(addedNodes) {
|
var surveyPhase1 = function(addedNodes) {
|
||||||
var t0 = window.performance.now(),
|
var t0 = window.performance.now(),
|
||||||
nodes = selectNodes('[class],[id]', addedNodes),
|
rews = reWhitespace,
|
||||||
qq = queriedSelectors,
|
qq = queriedSelectors,
|
||||||
ll = lowGenericSelectors,
|
ll = lowGenericSelectors,
|
||||||
node, v, vv, j,
|
lli = ll.length,
|
||||||
i = nodes.length;
|
nodes, i, node, v, vv, j;
|
||||||
|
nodes = selectNodes('[id]', addedNodes);
|
||||||
|
i = nodes.length;
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
node = nodes[i];
|
node = nodes[i];
|
||||||
if ( node.nodeType !== 1 ) { continue; }
|
|
||||||
v = node.id;
|
v = node.id;
|
||||||
if ( v !== '' && typeof v === 'string' ) {
|
if ( typeof v !== 'string' ) { continue; }
|
||||||
v = '#' + v.trim();
|
v = '#' + v.trim();
|
||||||
if ( v !== '#' && !qq.has(v) ) { ll.push(v); qq.add(v); }
|
if ( !qq.has(v) && v.length !== 1 ) {
|
||||||
|
ll[lli] = v; lli++; qq.add(v);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
nodes = selectNodes('[class]', addedNodes);
|
||||||
|
i = nodes.length;
|
||||||
|
while ( i-- ) {
|
||||||
|
node = nodes[i];
|
||||||
vv = node.className;
|
vv = node.className;
|
||||||
if ( vv === '' || typeof vv !== 'string' ) { continue; }
|
if ( typeof vv !== 'string' ) { continue; }
|
||||||
if ( /\s/.test(vv) === false ) {
|
if ( !rews.test(vv) ) {
|
||||||
v = '.' + vv;
|
v = '.' + vv;
|
||||||
if ( !qq.has(v) ) { ll.push(v); qq.add(v); }
|
if ( !qq.has(v) && v.length !== 1 ) {
|
||||||
|
ll[lli] = v; lli++; qq.add(v);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
vv = node.classList;
|
vv = node.classList;
|
||||||
j = vv.length;
|
j = vv.length;
|
||||||
while ( j-- ) {
|
while ( j-- ) {
|
||||||
v = '.' + vv[j];
|
v = '.' + vv[j];
|
||||||
if ( !qq.has(v) ) { ll.push(v); qq.add(v); }
|
if ( !qq.has(v) ) {
|
||||||
|
ll[lli] = v; lli++; qq.add(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
surveyCost += window.performance.now() - t0;
|
surveyCost += window.performance.now() - t0;
|
||||||
surveyPhase2(addedNodes);
|
surveyPhase2(addedNodes);
|
||||||
};
|
};
|
||||||
|
var reWhitespace = /\s/;
|
||||||
|
|
||||||
var domChangedHandler = function(addedNodes) {
|
var domChangedHandler = function(addedNodes) {
|
||||||
if ( cosmeticSurveyingMissCount > 255 ) {
|
if ( cosmeticSurveyingMissCount > 255 ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user