mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-22 05:37:41 +02:00
Compile scriptlet filters to their canonical, unaliased name
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1031
This commit is contained in:
parent
66c237f529
commit
a85a908f09
1 changed files with 15 additions and 11 deletions
|
@ -172,15 +172,19 @@
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// TODO: Probably should move this into StaticFilteringParser
|
// TODO: Probably should move this into StaticFilteringParser
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1031
|
||||||
|
// Normalize scriptlet name to its canonical, unaliased name.
|
||||||
const normalizeRawFilter = function(rawFilter) {
|
const normalizeRawFilter = function(rawFilter) {
|
||||||
let rawToken = rawFilter.slice(4, -1);
|
const rawToken = rawFilter.slice(4, -1);
|
||||||
let rawEnd = rawToken.length;
|
const rawEnd = rawToken.length;
|
||||||
let end = rawToken.indexOf(',');
|
let end = rawToken.indexOf(',');
|
||||||
if ( end === -1 ) {
|
if ( end === -1 ) { end = rawEnd; }
|
||||||
end = rawEnd;
|
const token = rawToken.slice(0, end).trim();
|
||||||
}
|
const alias = token.endsWith('.js') ? token.slice(0, -3) : token;
|
||||||
let token = rawToken.slice(0, end).trim();
|
let normalized = µb.redirectEngine.aliases.get(`${alias}.js`);
|
||||||
let normalized = token.endsWith('.js') ? token.slice(0, -3) : token;
|
normalized = normalized === undefined
|
||||||
|
? alias
|
||||||
|
: normalized.slice(0, -3);
|
||||||
let beg = end + 1;
|
let beg = end + 1;
|
||||||
while ( beg < rawEnd ) {
|
while ( beg < rawEnd ) {
|
||||||
end = rawToken.indexOf(',', beg);
|
end = rawToken.indexOf(',', beg);
|
||||||
|
@ -471,10 +475,10 @@
|
||||||
api.benchmark = async function() {
|
api.benchmark = async function() {
|
||||||
const requests = await µb.loadBenchmarkDataset();
|
const requests = await µb.loadBenchmarkDataset();
|
||||||
if ( Array.isArray(requests) === false || requests.length === 0 ) {
|
if ( Array.isArray(requests) === false || requests.length === 0 ) {
|
||||||
console.info('No requests found to benchmark');
|
log.print('No requests found to benchmark');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.info('Benchmarking scriptletFilteringEngine.retrieve()...');
|
log.print('Benchmarking scriptletFilteringEngine.retrieve()...');
|
||||||
const details = {
|
const details = {
|
||||||
domain: '',
|
domain: '',
|
||||||
entity: '',
|
entity: '',
|
||||||
|
@ -496,8 +500,8 @@
|
||||||
}
|
}
|
||||||
const t1 = self.performance.now();
|
const t1 = self.performance.now();
|
||||||
const dur = t1 - t0;
|
const dur = t1 - t0;
|
||||||
console.info(`Evaluated ${count} requests in ${dur.toFixed(0)} ms`);
|
log.print(`Evaluated ${count} requests in ${dur.toFixed(0)} ms`);
|
||||||
console.info(`\tAverage: ${(dur / count).toFixed(3)} ms per request`);
|
log.print(`\tAverage: ${(dur / count).toFixed(3)} ms per request`);
|
||||||
};
|
};
|
||||||
|
|
||||||
return api;
|
return api;
|
||||||
|
|
Loading…
Reference in a new issue