1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-05 10:22:30 +01:00

Rename module-scoped classes for better distinction in profiling data

This commit is contained in:
Raymond Hill 2024-03-02 09:41:12 -05:00
parent 7ab7104a54
commit a0a6ae0d0c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 52 additions and 52 deletions

View File

@ -221,7 +221,7 @@ const reEscapeSequence = /\\([0-9A-Fa-f]+ |.)/g;
// Generic filters can only be enforced once the main document is loaded.
// Specific filers can be enforced before the main document is loaded.
const FilterContainer = function() {
const CosmeticFilteringEngine = function() {
this.reSimpleHighGeneric = /^(?:[a-z]*\[[^\]]+\]|\S+)$/;
this.selectorCache = new Map();
@ -269,7 +269,7 @@ const FilterContainer = function() {
// Reset all, thus reducing to a minimum memory footprint of the context.
FilterContainer.prototype.reset = function() {
CosmeticFilteringEngine.prototype.reset = function() {
this.frozen = false;
this.acceptedCount = 0;
this.discardedCount = 0;
@ -297,7 +297,7 @@ FilterContainer.prototype.reset = function() {
/******************************************************************************/
FilterContainer.prototype.freeze = function() {
CosmeticFilteringEngine.prototype.freeze = function() {
this.duplicateBuster.clear();
this.specificFilters.collectGarbage();
@ -311,7 +311,7 @@ FilterContainer.prototype.freeze = function() {
/******************************************************************************/
FilterContainer.prototype.compile = function(parser, writer) {
CosmeticFilteringEngine.prototype.compile = function(parser, writer) {
if ( parser.hasOptions() === false ) {
this.compileGenericSelector(parser, writer);
return true;
@ -337,7 +337,7 @@ FilterContainer.prototype.compile = function(parser, writer) {
/******************************************************************************/
FilterContainer.prototype.compileGenericSelector = function(parser, writer) {
CosmeticFilteringEngine.prototype.compileGenericSelector = function(parser, writer) {
if ( parser.isException() ) {
this.compileGenericUnhideSelector(parser, writer);
} else {
@ -347,7 +347,7 @@ FilterContainer.prototype.compileGenericSelector = function(parser, writer) {
/******************************************************************************/
FilterContainer.prototype.compileGenericHideSelector = function(
CosmeticFilteringEngine.prototype.compileGenericHideSelector = function(
parser,
writer
) {
@ -403,7 +403,7 @@ FilterContainer.prototype.compileGenericHideSelector = function(
/******************************************************************************/
FilterContainer.prototype.compileGenericUnhideSelector = function(
CosmeticFilteringEngine.prototype.compileGenericUnhideSelector = function(
parser,
writer
) {
@ -432,7 +432,7 @@ FilterContainer.prototype.compileGenericUnhideSelector = function(
/******************************************************************************/
FilterContainer.prototype.compileSpecificSelector = function(
CosmeticFilteringEngine.prototype.compileSpecificSelector = function(
parser,
hostname,
not,
@ -471,7 +471,7 @@ FilterContainer.prototype.compileSpecificSelector = function(
/******************************************************************************/
FilterContainer.prototype.fromCompiledContent = function(reader, options) {
CosmeticFilteringEngine.prototype.fromCompiledContent = function(reader, options) {
if ( options.skipCosmetic ) {
this.skipCompiledContent(reader, 'SPECIFIC');
this.skipCompiledContent(reader, 'GENERIC');
@ -560,7 +560,7 @@ FilterContainer.prototype.fromCompiledContent = function(reader, options) {
/******************************************************************************/
FilterContainer.prototype.skipCompiledContent = function(reader, sectionId) {
CosmeticFilteringEngine.prototype.skipCompiledContent = function(reader, sectionId) {
reader.select(`COSMETIC_FILTERS:${sectionId}`);
while ( reader.next() ) {
this.acceptedCount += 1;
@ -570,7 +570,7 @@ FilterContainer.prototype.skipCompiledContent = function(reader, sectionId) {
/******************************************************************************/
FilterContainer.prototype.toSelfie = function() {
CosmeticFilteringEngine.prototype.toSelfie = function() {
return {
version: this.selfieVersion,
acceptedCount: this.acceptedCount,
@ -586,7 +586,7 @@ FilterContainer.prototype.toSelfie = function() {
/******************************************************************************/
FilterContainer.prototype.fromSelfie = function(selfie) {
CosmeticFilteringEngine.prototype.fromSelfie = function(selfie) {
if ( selfie.version !== this.selfieVersion ) {
throw new Error(
`cosmeticFilteringEngine: mismatched selfie version, ${selfie.version}, expected ${this.selfieVersion}`
@ -605,7 +605,7 @@ FilterContainer.prototype.fromSelfie = function(selfie) {
/******************************************************************************/
FilterContainer.prototype.addToSelectorCache = function(details) {
CosmeticFilteringEngine.prototype.addToSelectorCache = function(details) {
const hostname = details.hostname;
if ( typeof hostname !== 'string' || hostname === '' ) { return; }
const selectors = details.selectors;
@ -623,7 +623,7 @@ FilterContainer.prototype.addToSelectorCache = function(details) {
/******************************************************************************/
FilterContainer.prototype.removeFromSelectorCache = function(
CosmeticFilteringEngine.prototype.removeFromSelectorCache = function(
targetHostname = '*',
type = undefined
) {
@ -646,7 +646,7 @@ FilterContainer.prototype.removeFromSelectorCache = function(
/******************************************************************************/
FilterContainer.prototype.pruneSelectorCacheAsync = function() {
CosmeticFilteringEngine.prototype.pruneSelectorCacheAsync = function() {
if ( this.selectorCache.size <= this.selectorCacheCountMax ) { return; }
const cache = this.selectorCache;
const hostnames = Array.from(cache.keys())
@ -660,7 +660,7 @@ FilterContainer.prototype.pruneSelectorCacheAsync = function() {
/******************************************************************************/
FilterContainer.prototype.disableSurveyor = function(details) {
CosmeticFilteringEngine.prototype.disableSurveyor = function(details) {
const hostname = details.hostname;
if ( typeof hostname !== 'string' || hostname === '' ) { return; }
const cacheEntry = this.selectorCache.get(hostname);
@ -670,7 +670,7 @@ FilterContainer.prototype.disableSurveyor = function(details) {
/******************************************************************************/
FilterContainer.prototype.cssRuleFromProcedural = function(pfilter) {
CosmeticFilteringEngine.prototype.cssRuleFromProcedural = function(pfilter) {
if ( pfilter.cssable !== true ) { return; }
const { tasks, action } = pfilter;
let mq, selector;
@ -701,7 +701,7 @@ FilterContainer.prototype.cssRuleFromProcedural = function(pfilter) {
/******************************************************************************/
FilterContainer.prototype.retrieveGenericSelectors = function(request) {
CosmeticFilteringEngine.prototype.retrieveGenericSelectors = function(request) {
if ( this.lowlyGeneric.size === 0 ) { return; }
if ( Array.isArray(request.hashes) === false ) { return; }
if ( request.hashes.length === 0 ) { return; }
@ -759,7 +759,7 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) {
/******************************************************************************/
FilterContainer.prototype.retrieveSpecificSelectors = function(
CosmeticFilteringEngine.prototype.retrieveSpecificSelectors = function(
request,
options
) {
@ -951,13 +951,13 @@ FilterContainer.prototype.retrieveSpecificSelectors = function(
/******************************************************************************/
FilterContainer.prototype.getFilterCount = function() {
CosmeticFilteringEngine.prototype.getFilterCount = function() {
return this.acceptedCount - this.discardedCount;
};
/******************************************************************************/
FilterContainer.prototype.dump = function() {
CosmeticFilteringEngine.prototype.dump = function() {
const lowlyGenerics = [];
for ( const selectors of this.lowlyGeneric.values() ) {
lowlyGenerics.push(...selectors.split(',\n'));
@ -978,7 +978,7 @@ FilterContainer.prototype.dump = function() {
/******************************************************************************/
const cosmeticFilteringEngine = new FilterContainer();
const cosmeticFilteringEngine = new CosmeticFilteringEngine();
export default cosmeticFilteringEngine;

View File

@ -4049,7 +4049,7 @@ FilterCompiler.prototype.FILTER_UNSUPPORTED = 2;
/******************************************************************************/
/******************************************************************************/
const FilterContainer = function() {
const StaticNetFilteringEngine = function() {
this.compilerVersion = '10';
this.selfieVersion = '10';
@ -4067,7 +4067,7 @@ const FilterContainer = function() {
/******************************************************************************/
FilterContainer.prototype.prime = function() {
StaticNetFilteringEngine.prototype.prime = function() {
origHNTrieContainer.reset(
keyvalStore.getItem('SNFE.origHNTrieContainer.trieDetails')
);
@ -4079,7 +4079,7 @@ FilterContainer.prototype.prime = function() {
/******************************************************************************/
FilterContainer.prototype.reset = function() {
StaticNetFilteringEngine.prototype.reset = function() {
this.processedFilterCount = 0;
this.acceptedCount = 0;
this.discardedCount = 0;
@ -4113,7 +4113,7 @@ FilterContainer.prototype.reset = function() {
/******************************************************************************/
FilterContainer.prototype.freeze = function() {
StaticNetFilteringEngine.prototype.freeze = function() {
const unserialize = CompiledListReader.unserialize;
for ( const line of this.goodFilters ) {
@ -4210,7 +4210,7 @@ FilterContainer.prototype.freeze = function() {
/******************************************************************************/
FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...args) {
if ( op === 'begin' ) {
Object.assign(context, {
good: new Set(),
@ -4545,7 +4545,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
/******************************************************************************/
FilterContainer.prototype.addFilterUnit = function(
StaticNetFilteringEngine.prototype.addFilterUnit = function(
bits,
tokenHash,
inewunit
@ -4572,7 +4572,7 @@ FilterContainer.prototype.addFilterUnit = function(
/******************************************************************************/
FilterContainer.prototype.optimize = function(throttle = 0) {
StaticNetFilteringEngine.prototype.optimize = function(throttle = 0) {
if ( this.optimizeTaskId !== undefined ) {
dropTask(this.optimizeTaskId);
this.optimizeTaskId = undefined;
@ -4628,7 +4628,7 @@ FilterContainer.prototype.optimize = function(throttle = 0) {
/******************************************************************************/
FilterContainer.prototype.toSelfie = function() {
StaticNetFilteringEngine.prototype.toSelfie = function() {
this.optimize(0);
bidiTrieOptimize(true);
keyvalStore.setItem('SNFE.origHNTrieContainer.trieDetails',
@ -4649,7 +4649,7 @@ FilterContainer.prototype.toSelfie = function() {
};
};
FilterContainer.prototype.serialize = async function() {
StaticNetFilteringEngine.prototype.serialize = async function() {
const selfie = [];
const storage = {
put(name, data) {
@ -4662,7 +4662,7 @@ FilterContainer.prototype.serialize = async function() {
/******************************************************************************/
FilterContainer.prototype.fromSelfie = async function(selfie) {
StaticNetFilteringEngine.prototype.fromSelfie = async function(selfie) {
if ( typeof selfie !== 'object' || selfie === null ) { return; }
this.reset();
@ -4695,7 +4695,7 @@ FilterContainer.prototype.fromSelfie = async function(selfie) {
return true;
};
FilterContainer.prototype.unserialize = async function(s) {
StaticNetFilteringEngine.prototype.unserialize = async function(s) {
const selfie = new Map(JSON.parse(s));
const storage = {
async get(name) {
@ -4707,13 +4707,13 @@ FilterContainer.prototype.unserialize = async function(s) {
/******************************************************************************/
FilterContainer.prototype.createCompiler = function() {
StaticNetFilteringEngine.prototype.createCompiler = function() {
return new FilterCompiler();
};
/******************************************************************************/
FilterContainer.prototype.fromCompiled = function(reader) {
StaticNetFilteringEngine.prototype.fromCompiled = function(reader) {
reader.select('NETWORK_FILTERS:GOOD');
while ( reader.next() ) {
this.acceptedCount += 1;
@ -4732,7 +4732,7 @@ FilterContainer.prototype.fromCompiled = function(reader) {
/******************************************************************************/
FilterContainer.prototype.matchAndFetchModifiers = function(
StaticNetFilteringEngine.prototype.matchAndFetchModifiers = function(
fctxt,
modifierName
) {
@ -4909,7 +4909,7 @@ FilterContainer.prototype.matchAndFetchModifiers = function(
/******************************************************************************/
FilterContainer.prototype.realmMatchString = function(
StaticNetFilteringEngine.prototype.realmMatchString = function(
realmBits,
typeBits,
partyBits
@ -5036,7 +5036,7 @@ FilterContainer.prototype.realmMatchString = function(
// https://www.reddit.com/r/uBlockOrigin/comments/d6vxzj/
// Add support for `specifichide`.
FilterContainer.prototype.matchRequestReverse = function(type, url) {
StaticNetFilteringEngine.prototype.matchRequestReverse = function(type, url) {
const typeBits = typeNameToTypeValue[type] | 0x80000000;
// Prime tokenizer: we get a normalized URL in return.
@ -5085,7 +5085,7 @@ FilterContainer.prototype.matchRequestReverse = function(type, url) {
*
* @returns {integer} 0=no match, 1=block, 2=allow (exception)
*/
FilterContainer.prototype.matchRequest = function(fctxt, modifiers = 0) {
StaticNetFilteringEngine.prototype.matchRequest = function(fctxt, modifiers = 0) {
let typeBits = typeNameToTypeValue[fctxt.type];
if ( modifiers === 0 ) {
if ( typeBits === undefined ) {
@ -5132,7 +5132,7 @@ FilterContainer.prototype.matchRequest = function(fctxt, modifiers = 0) {
/******************************************************************************/
FilterContainer.prototype.matchHeaders = function(fctxt, headers) {
StaticNetFilteringEngine.prototype.matchHeaders = function(fctxt, headers) {
const typeBits = typeNameToTypeValue[fctxt.type] || otherTypeBitValue;
const partyBits = fctxt.is3rdPartyToDoc() ? THIRDPARTY_REALM : FIRSTPARTY_REALM;
@ -5169,7 +5169,7 @@ FilterContainer.prototype.matchHeaders = function(fctxt, headers) {
/******************************************************************************/
FilterContainer.prototype.redirectRequest = function(redirectEngine, fctxt) {
StaticNetFilteringEngine.prototype.redirectRequest = function(redirectEngine, fctxt) {
const directives = this.matchAndFetchModifiers(fctxt, 'redirect-rule');
// No directive is the most common occurrence.
if ( directives === undefined ) { return; }
@ -5187,7 +5187,7 @@ FilterContainer.prototype.redirectRequest = function(redirectEngine, fctxt) {
return directives;
};
FilterContainer.prototype.transformRequest = function(fctxt) {
StaticNetFilteringEngine.prototype.transformRequest = function(fctxt) {
const directives = this.matchAndFetchModifiers(fctxt, 'uritransform');
if ( directives === undefined ) { return; }
const redirectURL = new URL(fctxt.url);
@ -5251,7 +5251,7 @@ function compareRedirectRequests(redirectEngine, a, b) {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1626
// Do not redirect when the number of query parameters does not change.
FilterContainer.prototype.filterQuery = function(fctxt) {
StaticNetFilteringEngine.prototype.filterQuery = function(fctxt) {
const directives = this.matchAndFetchModifiers(fctxt, 'removeparam');
if ( directives === undefined ) { return; }
const url = fctxt.url;
@ -5345,14 +5345,14 @@ function parseQueryPruneValue(directive) {
/******************************************************************************/
FilterContainer.prototype.hasQuery = function(fctxt) {
StaticNetFilteringEngine.prototype.hasQuery = function(fctxt) {
urlTokenizer.setURL(fctxt.url);
return urlTokenizer.hasQuery();
};
/******************************************************************************/
FilterContainer.prototype.toLogData = function() {
StaticNetFilteringEngine.prototype.toLogData = function() {
if ( this.$filterUnit !== 0 ) {
return new LogData(this.$catBits, this.$tokenHash, this.$filterUnit);
}
@ -5360,19 +5360,19 @@ FilterContainer.prototype.toLogData = function() {
/******************************************************************************/
FilterContainer.prototype.isBlockImportant = function() {
StaticNetFilteringEngine.prototype.isBlockImportant = function() {
return this.$filterUnit !== 0 && $isBlockImportant;
};
/******************************************************************************/
FilterContainer.prototype.getFilterCount = function() {
StaticNetFilteringEngine.prototype.getFilterCount = function() {
return this.acceptedCount - this.discardedCount;
};
/******************************************************************************/
FilterContainer.prototype.enableWASM = function(wasmModuleFetcher, path) {
StaticNetFilteringEngine.prototype.enableWASM = function(wasmModuleFetcher, path) {
return Promise.all([
bidiTrie.enableWASM(wasmModuleFetcher, path),
origHNTrieContainer.enableWASM(wasmModuleFetcher, path),
@ -5384,7 +5384,7 @@ FilterContainer.prototype.enableWASM = function(wasmModuleFetcher, path) {
/******************************************************************************/
FilterContainer.prototype.test = async function(docURL, type, url) {
StaticNetFilteringEngine.prototype.test = async function(docURL, type, url) {
const fctxt = new FilteringContext();
fctxt.setDocOriginFromURL(docURL);
fctxt.setType(type);
@ -5398,7 +5398,7 @@ FilterContainer.prototype.test = async function(docURL, type, url) {
/******************************************************************************/
FilterContainer.prototype.bucketHistogram = function() {
StaticNetFilteringEngine.prototype.bucketHistogram = function() {
const results = [];
for ( const [ bits, bucket ] of this.bitsToBucket ) {
for ( const [ th, iunit ] of bucket ) {
@ -5419,7 +5419,7 @@ FilterContainer.prototype.bucketHistogram = function() {
// Dump the internal state of the filtering engine to the console.
// Useful to make development decisions and investigate issues.
FilterContainer.prototype.dump = function() {
StaticNetFilteringEngine.prototype.dump = function() {
const thConstants = new Map([
[ NO_TOKEN_HASH, 'NO_TOKEN_HASH' ],
[ DOT_TOKEN_HASH, 'DOT_TOKEN_HASH' ],
@ -5549,6 +5549,6 @@ FilterContainer.prototype.dump = function() {
/******************************************************************************/
const staticNetFilteringEngine = new FilterContainer();
const staticNetFilteringEngine = new StaticNetFilteringEngine();
export default staticNetFilteringEngine;