mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
Code review related to performance in main content script
- Avoid concatenating with empty array: though the concatenated array is empty, this still forces the creation of a whole new array as per semantic of Array.prototype.concat(). <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat> - Do not convert arrays to strings when sending data to main process in surveyPhase1(): I no longer see any benefit doing so in profiling data (if I recall properly this was benefiting Firefox, but I can't remember for sure anymore why I chose to do so back then).
This commit is contained in:
parent
4ce1796f09
commit
f35dff2c9d
@ -1147,7 +1147,9 @@ vAPI.domSurveyor = (function() {
|
|||||||
pending.nodes = added;
|
pending.nodes = added;
|
||||||
} else {
|
} else {
|
||||||
nodes = pending.nodes.splice(0, 1000);
|
nodes = pending.nodes.splice(0, 1000);
|
||||||
pending.nodes = pending.nodes.concat(added);
|
if ( added.length !== 0 ) {
|
||||||
|
pending.nodes = pending.nodes.concat(added);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
@ -1212,8 +1214,8 @@ vAPI.domSurveyor = (function() {
|
|||||||
{
|
{
|
||||||
what: 'retrieveGenericCosmeticSelectors',
|
what: 'retrieveGenericCosmeticSelectors',
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
ids: ids.join('\n'),
|
ids: ids,
|
||||||
classes: classes.join('\n'),
|
classes: classes,
|
||||||
exceptions: domFilterer.exceptions,
|
exceptions: domFilterer.exceptions,
|
||||||
cost: surveyCost
|
cost: surveyCost
|
||||||
},
|
},
|
||||||
|
@ -1054,14 +1054,8 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) {
|
|||||||
for ( let type in this.lowlyGeneric ) {
|
for ( let type in this.lowlyGeneric ) {
|
||||||
let entry = this.lowlyGeneric[type];
|
let entry = this.lowlyGeneric[type];
|
||||||
let selectors = request[entry.canonical];
|
let selectors = request[entry.canonical];
|
||||||
if ( typeof selectors !== 'string' ) { continue; }
|
if ( Array.isArray(selectors) === false ) { continue; }
|
||||||
let strEnd = selectors.length;
|
for ( let selector of selectors ) {
|
||||||
let sliceBeg = 0;
|
|
||||||
do {
|
|
||||||
let sliceEnd = selectors.indexOf('\n', sliceBeg);
|
|
||||||
if ( sliceEnd === -1 ) { sliceEnd = strEnd; }
|
|
||||||
let selector = selectors.slice(sliceBeg, sliceEnd);
|
|
||||||
sliceBeg = sliceEnd + 1;
|
|
||||||
if ( entry.simple.has(selector) === false ) { continue; }
|
if ( entry.simple.has(selector) === false ) { continue; }
|
||||||
let bucket = entry.complex.get(selector);
|
let bucket = entry.complex.get(selector);
|
||||||
if ( bucket !== undefined ) {
|
if ( bucket !== undefined ) {
|
||||||
@ -1080,7 +1074,7 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) {
|
|||||||
simpleSelectors.add(selector);
|
simpleSelectors.add(selector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while ( sliceBeg < strEnd );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply exceptions: it is the responsibility of the caller to provide
|
// Apply exceptions: it is the responsibility of the caller to provide
|
||||||
|
Loading…
Reference in New Issue
Block a user