mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-01 16:33:06 +01:00
Reuse duplicate strings stored in tries
This is particularly helpful for static network filters used with filter options causing the same pattern to be reused across multiple filter instances, i.e. `all` or `~css`, etc.
This commit is contained in:
parent
e8e4a1ac74
commit
c77f697b4b
@ -141,6 +141,9 @@ const HNTrieContainer = class {
|
||||
this.buf32[CHAR0_SLOT] = len >>> 1;
|
||||
this.buf32[CHAR1_SLOT] = this.buf32[CHAR0_SLOT];
|
||||
this.wasmMemory = null;
|
||||
|
||||
this.lastStored = '';
|
||||
this.lastStoredLen = this.lastStoredIndex = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -160,6 +163,9 @@ const HNTrieContainer = class {
|
||||
}
|
||||
this.buf32[TRIE1_SLOT] = this.buf32[TRIE0_SLOT];
|
||||
this.buf32[CHAR1_SLOT] = this.buf32[CHAR0_SLOT];
|
||||
|
||||
this.lastStored = '';
|
||||
this.lastStoredLen = this.lastStoredIndex = 0;
|
||||
}
|
||||
|
||||
setNeedle(needle) {
|
||||
@ -419,6 +425,11 @@ const HNTrieContainer = class {
|
||||
hn = hn.slice(-255);
|
||||
n = 255;
|
||||
}
|
||||
if ( n === this.lastStoredLen && hn === this.lastStored ) {
|
||||
return this.lastStoredIndex;
|
||||
}
|
||||
this.lastStored = hn;
|
||||
this.lastStoredLen = n;
|
||||
if ( (this.buf.length - this.buf32[CHAR1_SLOT]) < n ) {
|
||||
this.growBuf(0, n);
|
||||
}
|
||||
@ -428,7 +439,7 @@ const HNTrieContainer = class {
|
||||
for ( let i = 0; i < n; i++ ) {
|
||||
buf8[offset+i] = hn.charCodeAt(i);
|
||||
}
|
||||
return offset - this.buf32[CHAR0_SLOT];
|
||||
return (this.lastStoredIndex = offset - this.buf32[CHAR0_SLOT]);
|
||||
}
|
||||
|
||||
extractHostname(i, n) {
|
||||
|
@ -147,6 +147,9 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
|
||||
this.extraHandler = extraHandler;
|
||||
this.textDecoder = null;
|
||||
this.wasmMemory = null;
|
||||
|
||||
this.lastStored = '';
|
||||
this.lastStoredLen = this.lastStoredIndex = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -174,6 +177,9 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
|
||||
}
|
||||
this.buf32[TRIE1_SLOT] = this.buf32[TRIE0_SLOT];
|
||||
this.buf32[CHAR1_SLOT] = this.buf32[CHAR0_SLOT];
|
||||
|
||||
this.lastStored = '';
|
||||
this.lastStoredLen = this.lastStoredIndex = 0;
|
||||
}
|
||||
|
||||
matches(icell, ai) {
|
||||
@ -602,6 +608,11 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
|
||||
|
||||
storeString(s) {
|
||||
const n = s.length;
|
||||
if ( n === this.lastStoredLen && s === this.lastStored ) {
|
||||
return this.lastStoredIndex;
|
||||
}
|
||||
this.lastStored = s;
|
||||
this.lastStoredLen = n;
|
||||
if ( (this.buf8.length - this.buf32[CHAR1_SLOT]) < n ) {
|
||||
this.growBuf(0, n);
|
||||
}
|
||||
@ -611,7 +622,7 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
|
||||
for ( let i = 0; i < n; i++ ) {
|
||||
buf8[offset+i] = s.charCodeAt(i);
|
||||
}
|
||||
return offset - this.buf32[CHAR0_SLOT];
|
||||
return (this.lastStoredIndex = offset - this.buf32[CHAR0_SLOT]);
|
||||
}
|
||||
|
||||
extractString(i, n) {
|
||||
|
Loading…
Reference in New Issue
Block a user