Rename register-like variables

Use leading `$` instead of trailing `$` to denote
register-like variables, this conveniently allows
to group them together in the debugger.
This commit is contained in:
Raymond Hill 2019-09-29 13:21:09 -04:00
parent bf99623a54
commit a8df19fee4
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 73 additions and 70 deletions

View File

@ -247,12 +247,12 @@ const FilterContainer = function() {
// is to prevent repeated allocation/deallocation overheads -- the
// constructors/destructors of javascript Set/Map is assumed to be costlier
// than just calling clear() on these.
this.simpleSet$ = new Set();
this.complexSet$ = new Set();
this.specificSet$ = new Set();
this.exceptionSet$ = new Set();
this.proceduralSet$ = new Set();
this.dummySet$ = new Set();
this.$simpleSet = new Set();
this.$complexSet = new Set();
this.$specificSet = new Set();
this.$exceptionSet = new Set();
this.$proceduralSet = new Set();
this.$dummySet = new Set();
this.reset();
};
@ -847,11 +847,11 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) {
//console.time('cosmeticFilteringEngine.retrieveGenericSelectors');
const simpleSelectors = this.simpleSet$;
const complexSelectors = this.complexSet$;
const simpleSelectors = this.$simpleSet;
const complexSelectors = this.$complexSet;
const cacheEntry = this.selectorCache.get(request.hostname);
const previousHits = cacheEntry && cacheEntry.cosmetic || this.dummySet$;
const previousHits = cacheEntry && cacheEntry.cosmetic || this.$dummySet;
for ( const type in this.lowlyGeneric ) {
const entry = this.lowlyGeneric[type];
@ -991,10 +991,10 @@ FilterContainer.prototype.retrieveSpecificSelectors = function(
};
if ( options.noCosmeticFiltering !== true ) {
const specificSet = this.specificSet$;
const proceduralSet = this.proceduralSet$;
const exceptionSet = this.exceptionSet$;
const dummySet = this.dummySet$;
const specificSet = this.$specificSet;
const proceduralSet = this.$proceduralSet;
const exceptionSet = this.$exceptionSet;
const dummySet = this.$dummySet;
// Cached cosmetic filters: these are always declarative.
if ( cacheEntry !== undefined ) {

View File

@ -354,9 +354,9 @@
return sessionScriptletDB;
};
const scriptlets$ = new Set();
const exceptions$ = new Set();
const scriptletToCodeMap$ = new Map();
const $scriptlets = new Set();
const $exceptions = new Set();
const $scriptletToCodeMap = new Map();
api.retrieve = function(request) {
if ( scriptletDB.size === 0 ) { return; }
@ -376,41 +376,41 @@
return;
}
scriptlets$.clear();
exceptions$.clear();
$scriptlets.clear();
$exceptions.clear();
if ( sessionScriptletDB.isNotEmpty ) {
sessionScriptletDB.retrieve([ null, exceptions$ ]);
sessionScriptletDB.retrieve([ null, $exceptions ]);
}
scriptletDB.retrieve(hostname, [ scriptlets$, exceptions$ ]);
scriptletDB.retrieve(hostname, [ $scriptlets, $exceptions ]);
if ( request.entity !== '' ) {
scriptletDB.retrieve(
`${hostname.slice(0, -request.domain.length)}${request.entity}`,
[ scriptlets$, exceptions$ ]
[ $scriptlets, $exceptions ]
);
}
if ( scriptlets$.size === 0 ) { return; }
if ( $scriptlets.size === 0 ) { return; }
const loggerEnabled = µb.logger.enabled;
// Wholly disable scriptlet injection?
if ( exceptions$.has('') ) {
if ( $exceptions.has('') ) {
if ( loggerEnabled ) {
logOne(true, '', request);
}
return;
}
scriptletToCodeMap$.clear();
for ( const rawToken of scriptlets$ ) {
lookupScriptlet(rawToken, reng, scriptletToCodeMap$);
$scriptletToCodeMap.clear();
for ( const rawToken of $scriptlets ) {
lookupScriptlet(rawToken, reng, $scriptletToCodeMap);
}
if ( scriptletToCodeMap$.size === 0 ) { return; }
if ( $scriptletToCodeMap.size === 0 ) { return; }
// Return an array of scriptlets, and log results if needed.
const out = [];
for ( const [ rawToken, code ] of scriptletToCodeMap$ ) {
const isException = exceptions$.has(rawToken);
for ( const [ rawToken, code ] of $scriptletToCodeMap ) {
const isException = $exceptions.has(rawToken);
if ( isException === false ) {
out.push(code);
}

View File

@ -170,9 +170,9 @@ const reIsWildcarded = /[\^\*]/;
// See the following as short-lived registers, used during evaluation. They are
// valid until the next evaluation.
let urlRegister = '';
let pageHostnameRegister = '';
let requestHostnameRegister = '';
let $requestURL = '';
let $requestHostname = '';
let $docHostname = '';
/******************************************************************************/
@ -185,7 +185,7 @@ const isHnAnchored = (( ) => {
let lastLen = 0, lastBeg = -1, lastEnd = -1;
return (url, matchStart) => {
const len = requestHostnameRegister.length;
const len = $requestHostname.length;
if ( len !== lastLen || url.endsWith('://', lastBeg) === false ) {
lastBeg = len !== 0 ? url.indexOf('://') : -1;
if ( lastBeg !== -1 ) {
@ -434,7 +434,7 @@ const FilterPlainHostname = class {
}
match() {
const haystack = requestHostnameRegister;
const haystack = $requestHostname;
const needle = this.s;
if ( haystack.endsWith(needle) === false ) { return false; }
const offset = haystack.length - needle.length;
@ -1097,7 +1097,7 @@ const FilterOriginHit = class {
}
match(url, tokenBeg) {
const haystack = pageHostnameRegister;
const haystack = $docHostname;
const offset = haystack.length - this.hostname.length;
if ( offset < 0 ) { return false; }
if ( haystack.charCodeAt(offset) !== this.hostname.charCodeAt(0) ) {
@ -1146,7 +1146,7 @@ const FilterOriginMiss = class {
}
match(url, tokenBeg) {
const haystack = pageHostnameRegister;
const haystack = $docHostname;
if ( haystack.endsWith(this.hostname) ) {
const offset = haystack.length - this.hostname.length;
if (
@ -1202,7 +1202,7 @@ const FilterOriginHitSet = class {
filterOrigin.strFromSlotId(this.domainOpt).split('|')
);
}
return this.oneOf.matches(pageHostnameRegister) !== -1 &&
return this.oneOf.matches($docHostname) !== -1 &&
this.wrapped.match(url, tokenBeg);
}
@ -1260,7 +1260,7 @@ const FilterOriginMissSet = class {
.split('|')
);
}
return this.noneOf.matches(pageHostnameRegister) === -1 &&
return this.noneOf.matches($docHostname) === -1 &&
this.wrapped.match(url, tokenBeg);
}
@ -1328,7 +1328,7 @@ const FilterOriginMixedSet = class {
match(url, tokenBeg) {
if ( this.oneOf === null ) { this.init(); }
let needle = pageHostnameRegister;
let needle = $docHostname;
return this.oneOf.matches(needle) !== -1 &&
this.noneOf.matches(needle) === -1 &&
this.wrapped.match(url, tokenBeg);
@ -1470,9 +1470,9 @@ const FilterHostnameDict = class {
}
match() {
const pos = this.dict.matches(requestHostnameRegister);
const pos = this.dict.matches($requestHostname);
if ( pos === -1 ) { return false; }
this.h = requestHostnameRegister.slice(pos);
this.h = $requestHostname.slice(pos);
return true;
}
@ -1542,9 +1542,9 @@ const FilterJustOrigin = class {
}
match() {
const pos = this.dict.matches(pageHostnameRegister);
const pos = this.dict.matches($docHostname);
if ( pos === -1 ) { return false; }
this.h = pageHostnameRegister.slice(pos);
this.h = $docHostname.slice(pos);
return true;
}
@ -1769,7 +1769,7 @@ const FilterBucket = class {
this.f === this.plainFilter ||
this.f === this.plainHnAnchoredFilter
) {
this.f.s = urlRegister.slice(
this.f.s = $requestURL.slice(
this.trieResult >>> 16,
this.trieResult & 0xFFFF
);
@ -2417,9 +2417,9 @@ FilterContainer.prototype.reset = function() {
FilterBucket.reset();
// Runtime registers
this.catbitsRegister = 0;
this.tokenRegister = 0;
this.filterRegister = null;
this.$catbits = 0;
this.$tokenHash = 0;
this.$filter = null;
};
/******************************************************************************/
@ -2848,7 +2848,7 @@ FilterContainer.prototype.realmMatchAndFetchData = function(
if ( bucket01 === undefined && bucket11 === undefined ) { return false; }
const url = urlRegister;
const url = $requestURL;
const tokenHashes = this.urlTokenizer.getTokens();
const filters = [];
let i = 0, tokenBeg = 0, f;
@ -2883,9 +2883,9 @@ FilterContainer.prototype.realmMatchAndFetchData = function(
/******************************************************************************/
FilterContainer.prototype.matchAndFetchData = function(fctxt, type) {
urlRegister = this.urlTokenizer.setURL(fctxt.url);
pageHostnameRegister = fctxt.getDocHostname();
requestHostnameRegister = fctxt.getHostname();
$requestURL = this.urlTokenizer.setURL(fctxt.url);
$docHostname = fctxt.getDocHostname();
$requestHostname = fctxt.getHostname();
const partyBits = fctxt.is3rdPartyToDoc() ? ThirdParty : FirstParty;
@ -3003,7 +3003,7 @@ FilterContainer.prototype.realmMatchString = function(
}
// Pattern-based filters
else {
const url = urlRegister;
const url = $requestURL;
const tokenHashes = this.urlTokenizer.getTokens();
let i = 0, tokenBeg = 0;
for (;;) {
@ -3046,9 +3046,9 @@ FilterContainer.prototype.realmMatchString = function(
}
}
this.catbitsRegister = catBits;
this.tokenRegister = tokenHash;
this.filterRegister = f;
this.$catbits = catBits;
this.$tokenHash = tokenHash;
this.$filter = f;
return true;
};
@ -3069,12 +3069,11 @@ FilterContainer.prototype.matchStringElementHide = function(type, url) {
const typeBits = typeNameToTypeValue[`${type}hide`] | 0x80000000;
// Prime tokenizer: we get a normalized URL in return.
urlRegister = this.urlTokenizer.setURL(url);
this.filterRegister = null;
$requestURL = this.urlTokenizer.setURL(url);
this.$filter = null;
// These registers will be used by various filters
pageHostnameRegister = requestHostnameRegister =
µb.URI.hostnameFromURI(url);
$docHostname = $requestHostname = µb.URI.hostnameFromURI(url);
// Exception filters
if ( this.realmMatchString(AllowAction, typeBits, FirstParty) ) {
@ -3114,12 +3113,12 @@ FilterContainer.prototype.matchString = function(fctxt, modifiers = 0) {
const partyBits = fctxt.is3rdPartyToDoc() ? ThirdParty : FirstParty;
// Prime tokenizer: we get a normalized URL in return.
urlRegister = this.urlTokenizer.setURL(fctxt.url);
this.filterRegister = null;
$requestURL = this.urlTokenizer.setURL(fctxt.url);
this.$filter = null;
// These registers will be used by various filters
pageHostnameRegister = fctxt.getDocHostname();
requestHostnameRegister = fctxt.getHostname();
$docHostname = fctxt.getDocHostname();
$requestHostname = fctxt.getHostname();
// Important block filters.
if ( this.realmMatchString(BlockImportant, typeBits, partyBits) ) {
@ -3139,17 +3138,21 @@ FilterContainer.prototype.matchString = function(fctxt, modifiers = 0) {
/******************************************************************************/
FilterContainer.prototype.toLogData = function() {
if ( this.filterRegister === null ) { return; }
if ( this.$filter === null ) { return; }
const logData = toLogDataInternal(
this.catbitsRegister,
this.tokenRegister,
this.filterRegister
this.$catbits,
this.$tokenHash,
this.$filter
);
logData.source = 'static';
logData.tokenHash = this.tokenRegister;
logData.result = this.filterRegister === null
logData.tokenHash = this.$tokenHash;
logData.result = this.$filter === null
? 0
: (this.catbitsRegister & 1 ? 2 : 1);
: (
(this.$catbits & 1) !== 0
? 2
: 1
);
return logData;
};