Minor code reivew of 4430ec11e2

This commit is contained in:
Raymond Hill 2019-05-23 08:15:26 -04:00
parent 7b8c087fdd
commit 1f398134f9
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -2910,106 +2910,99 @@ FilterContainer.prototype.realmMatchString = function(
const catBits11 = realmBits | typeBits | partyBits; const catBits11 = realmBits | typeBits | partyBits;
const bucket00 = exactType === 0 const bucket00 = exactType === 0
? this.categories.get(catBits00) || null ? this.categories.get(catBits00)
: null; : undefined;
const bucket01 = exactType !== 0 || typeBits !== 0 const bucket01 = exactType !== 0 || typeBits !== 0
? this.categories.get(catBits01) || null ? this.categories.get(catBits01)
: null; : undefined;
const bucket10 = exactType === 0 && partyBits !== 0 const bucket10 = exactType === 0 && partyBits !== 0
? this.categories.get(catBits10) || null ? this.categories.get(catBits10)
: null; : undefined;
const bucket11 = (exactType !== 0 || typeBits !== 0) && partyBits !== 0 const bucket11 = (exactType !== 0 || typeBits !== 0) && partyBits !== 0
? this.categories.get(catBits11) || null ? this.categories.get(catBits11)
: null; : undefined;
if ( if (
bucket00 === null && bucket01 === null && bucket00 === undefined && bucket01 === undefined &&
bucket10 === null && bucket11 === null bucket10 === undefined && bucket11 === undefined
) { ) {
return false; return false;
} }
let catBits = 0; let catBits = 0, f;
// Pure hostname-based filters // Pure hostname-based filters
let tokenHash = this.dotTokenHash; let tokenHash = this.dotTokenHash;
let f;
if ( if (
(bucket00 !== null) && (bucket00 !== undefined) &&
(f = bucket00.get(tokenHash)) !== undefined && (f = bucket00.get(tokenHash)) !== undefined &&
(f.match() === true) (f.match() === true)
) { ) {
catBits = catBits00; catBits = catBits00;
} else if ( } else if (
(bucket01 !== null) && (bucket01 !== undefined) &&
(f = bucket01.get(tokenHash)) !== undefined && (f = bucket01.get(tokenHash)) !== undefined &&
(f.match() === true) (f.match() === true)
) { ) {
catBits = catBits01; catBits = catBits01;
} else if ( } else if (
(bucket10 !== null) && (bucket10 !== undefined) &&
(f = bucket10.get(tokenHash)) !== undefined && (f = bucket10.get(tokenHash)) !== undefined &&
(f.match() === true) (f.match() === true)
) { ) {
catBits = catBits10; catBits = catBits10;
} else if ( } else if (
(bucket11 !== null) && (bucket11 !== undefined) &&
(f = bucket11.get(tokenHash)) !== undefined && (f = bucket11.get(tokenHash)) !== undefined &&
(f.match() === true) (f.match() === true)
) { ) {
catBits = catBits11; catBits = catBits11;
} else {
f = undefined;
} }
if ( f !== undefined ) { // Pattern-based filters
this.catbitsRegister = catBits; else {
this.tokenRegister = tokenHash; const url = this.urlRegister;
this.filterRegister = f; const tokenHashes = this.urlTokenizer.getTokens();
return true; let i = 0, tokenBeg = 0;
for (;;) {
tokenHash = tokenHashes[i];
if ( tokenHash === 0 ) { return false; }
tokenBeg = tokenHashes[i+1];
if (
(bucket00 !== undefined) &&
(f = bucket00.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits00;
break;
}
if (
(bucket01 !== undefined) &&
(f = bucket01.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits01;
break;
}
if (
(bucket10 !== undefined) &&
(f = bucket10.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits10;
break;
}
if (
(bucket11 !== undefined) &&
(f = bucket11.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits11;
break;
}
i += 2;
}
} }
// Pattern-based filters
const url = this.urlRegister;
const tokenHashes = this.urlTokenizer.getTokens();
let i = 0, tokenBeg = 0;
for (;;) {
tokenHash = tokenHashes[i];
if ( tokenHash === 0 ) { return false; }
tokenBeg = tokenHashes[i+1];
if (
(bucket00 !== null) &&
(f = bucket00.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits00;
break;
}
if (
(bucket01 !== null) &&
(f = bucket01.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits01;
break;
}
if (
(bucket10 !== null) &&
(f = bucket10.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits10;
break;
}
if (
(bucket11 !== null) &&
(f = bucket11.get(tokenHash)) !== undefined &&
(f.match(url, tokenBeg) === true)
) {
catBits = catBits11;
break;
}
i += 2;
}
this.catbitsRegister = catBits; this.catbitsRegister = catBits;
this.tokenRegister = tokenHash; this.tokenRegister = tokenHash;
this.filterRegister = f; this.filterRegister = f;