mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 17:41:03 +01:00
Update PSL library to last version
This commit is contained in:
parent
e06cf1de9b
commit
1e2969c3b0
1 changed files with 41 additions and 23 deletions
|
@ -52,9 +52,9 @@
|
||||||
Tree encoding in array buffer:
|
Tree encoding in array buffer:
|
||||||
|
|
||||||
Node:
|
Node:
|
||||||
+ u16: length of array of children
|
|
||||||
+ u8: flags => bit 0: is_publicsuffix, bit 1: is_exception
|
|
||||||
+ u8: length of char data
|
+ u8: length of char data
|
||||||
|
+ u8: flags => bit 0: is_publicsuffix, bit 1: is_exception
|
||||||
|
+ u16: length of array of children
|
||||||
+ u32: char data or offset to char data
|
+ u32: char data or offset to char data
|
||||||
+ u32: offset to array of children
|
+ u32: offset to array of children
|
||||||
= 12 bytes
|
= 12 bytes
|
||||||
|
@ -473,29 +473,46 @@ const getDomain = function(hostname) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const toSelfie = function() {
|
const toSelfie = function(encoder) {
|
||||||
const selfie = {
|
if ( pslBuffer8 === undefined ) { return ''; }
|
||||||
|
if ( encoder instanceof Object ) {
|
||||||
|
const bufferStr = encoder.encode(pslBuffer8.buffer, pslByteLength);
|
||||||
|
return `${SELFIE_MAGIC}\t${bufferStr}`;
|
||||||
|
}
|
||||||
|
return {
|
||||||
magic: SELFIE_MAGIC,
|
magic: SELFIE_MAGIC,
|
||||||
byteLength: pslByteLength,
|
buf32: Array.from(
|
||||||
buffer: pslBuffer32 !== undefined
|
new Uint32Array(this.buf32.buffer, 0, pslByteLength >>> 2)
|
||||||
? Array.from(new Uint32Array(pslBuffer32.buffer, 0, pslByteLength >>> 2))
|
),
|
||||||
: null,
|
|
||||||
};
|
};
|
||||||
return selfie;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const fromSelfie = function(selfie) {
|
const fromSelfie = function(selfie, decoder) {
|
||||||
|
let byteLength = 0;
|
||||||
if (
|
if (
|
||||||
selfie instanceof Object === false ||
|
typeof selfie === 'string' &&
|
||||||
selfie.magic !== SELFIE_MAGIC ||
|
selfie.length !== 0 &&
|
||||||
typeof selfie.byteLength !== 'number' ||
|
decoder instanceof Object
|
||||||
Array.isArray(selfie.buffer) === false
|
|
||||||
) {
|
) {
|
||||||
|
const pos = selfie.indexOf('\t');
|
||||||
|
if ( pos === -1 || selfie.slice(0, pos) !== `${SELFIE_MAGIC}` ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const bufferStr = selfie.slice(pos + 1);
|
||||||
|
byteLength = decoder.decodeSize(bufferStr);
|
||||||
|
allocateBuffers(byteLength);
|
||||||
|
decoder.decode(bufferStr, pslBuffer8.buffer);
|
||||||
|
} else if (
|
||||||
|
selfie instanceof Object &&
|
||||||
|
selfie.magic === SELFIE_MAGIC &&
|
||||||
|
Array.isArray(selfie.buf32)
|
||||||
|
) {
|
||||||
|
byteLength = selfie.buf32.length << 2;
|
||||||
|
allocateBuffers(byteLength);
|
||||||
|
pslBuffer32.set(selfie.buf32);
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocateBuffers(selfie.byteLength);
|
|
||||||
pslBuffer32.set(selfie.buffer);
|
|
||||||
|
|
||||||
// Important!
|
// Important!
|
||||||
hostnameArg = '';
|
hostnameArg = '';
|
||||||
|
@ -568,13 +585,13 @@ const enableWASM = (function() {
|
||||||
if ( newPageCount > curPageCount ) {
|
if ( newPageCount > curPageCount ) {
|
||||||
memory.grow(newPageCount - curPageCount);
|
memory.grow(newPageCount - curPageCount);
|
||||||
}
|
}
|
||||||
|
if ( pslBuffer32 !== undefined ) {
|
||||||
const buf8 = new Uint8Array(memory.buffer);
|
const buf8 = new Uint8Array(memory.buffer);
|
||||||
const buf32 = new Uint32Array(memory.buffer);
|
const buf32 = new Uint32Array(memory.buffer);
|
||||||
if ( pslBuffer32 !== undefined ) {
|
|
||||||
buf32.set(pslBuffer32);
|
buf32.set(pslBuffer32);
|
||||||
}
|
|
||||||
pslBuffer8 = buf8;
|
pslBuffer8 = buf8;
|
||||||
pslBuffer32 = buf32;
|
pslBuffer32 = buf32;
|
||||||
|
}
|
||||||
wasmMemory = memory;
|
wasmMemory = memory;
|
||||||
getPublicSuffixPosWASM = instance.exports.getPublicSuffixPos;
|
getPublicSuffixPosWASM = instance.exports.getPublicSuffixPos;
|
||||||
getPublicSuffixPos = getPublicSuffixPosWASM;
|
getPublicSuffixPos = getPublicSuffixPosWASM;
|
||||||
|
@ -592,14 +609,15 @@ const disableWASM = function() {
|
||||||
getPublicSuffixPos = getPublicSuffixPosJS;
|
getPublicSuffixPos = getPublicSuffixPosJS;
|
||||||
getPublicSuffixPosWASM = undefined;
|
getPublicSuffixPosWASM = undefined;
|
||||||
}
|
}
|
||||||
if ( wasmMemory !== undefined ) {
|
if ( wasmMemory === undefined ) { return; }
|
||||||
|
if ( pslBuffer32 !== undefined ) {
|
||||||
const buf8 = new Uint8Array(pslByteLength);
|
const buf8 = new Uint8Array(pslByteLength);
|
||||||
const buf32 = new Uint32Array(buf8.buffer);
|
const buf32 = new Uint32Array(buf8.buffer);
|
||||||
buf32.set(pslBuffer32);
|
buf32.set(pslBuffer32);
|
||||||
pslBuffer8 = buf8;
|
pslBuffer8 = buf8;
|
||||||
pslBuffer32 = buf32;
|
pslBuffer32 = buf32;
|
||||||
wasmMemory = undefined;
|
|
||||||
}
|
}
|
||||||
|
wasmMemory = undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
Loading…
Reference in a new issue