mirror of https://github.com/gorhill/uBlock.git
Fix uselessly allocating one extra WASM page
spotted as a result of stepping in the code. The issue is that a uBP "page size" might differ from a WASM page size, which is always 65536 bytes.
This commit is contained in:
parent
2ded039b98
commit
4fa5c6b88e
|
@ -411,25 +411,20 @@ const HNTrieContainer = class {
|
|||
if ( typeof WebAssembly !== 'object' ) { return false; }
|
||||
if ( this.wasmMemory instanceof WebAssembly.Memory ) { return true; }
|
||||
const module = await getWasmModule();
|
||||
if ( module instanceof WebAssembly.Module === false ) {
|
||||
return false;
|
||||
}
|
||||
if ( module instanceof WebAssembly.Module === false ) { return false; }
|
||||
const memory = new WebAssembly.Memory({ initial: 2 });
|
||||
const instance = await WebAssembly.instantiate(
|
||||
module,
|
||||
{
|
||||
imports: {
|
||||
memory,
|
||||
growBuf: this.growBuf.bind(this, 24, 256)
|
||||
}
|
||||
const instance = await WebAssembly.instantiate(module, {
|
||||
imports: {
|
||||
memory,
|
||||
growBuf: this.growBuf.bind(this, 24, 256)
|
||||
}
|
||||
);
|
||||
});
|
||||
if ( instance instanceof WebAssembly.Instance === false ) {
|
||||
return false;
|
||||
}
|
||||
this.wasmMemory = memory;
|
||||
const curPageCount = memory.buffer.byteLength >>> 16;
|
||||
const newPageCount = this.buf.byteLength + PAGE_SIZE-1 >>> 16;
|
||||
const newPageCount = roundToPageSize(this.buf.byteLength) >>> 16;
|
||||
if ( newPageCount > curPageCount ) {
|
||||
memory.grow(newPageCount - curPageCount);
|
||||
}
|
||||
|
|
|
@ -690,22 +690,19 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
|
|||
if ( typeof WebAssembly !== 'object' ) { return false; }
|
||||
if ( this.wasmMemory instanceof WebAssembly.Memory ) { return true; }
|
||||
const module = await getWasmModule();
|
||||
if ( module instanceof WebAssembly.Module === false ) {
|
||||
return false;
|
||||
}
|
||||
if ( module instanceof WebAssembly.Module === false ) { return false; }
|
||||
const memory = new WebAssembly.Memory({
|
||||
initial: this.buf8.length >>> 16
|
||||
initial: roundToPageSize(this.buf8.length) >>> 16
|
||||
});
|
||||
const instance = await WebAssembly.instantiate(module, {
|
||||
imports: { memory, extraHandler: this.extraHandler }
|
||||
});
|
||||
const instance = await WebAssembly.instantiate(
|
||||
module,
|
||||
{ imports: { memory, extraHandler: this.extraHandler } }
|
||||
);
|
||||
if ( instance instanceof WebAssembly.Instance === false ) {
|
||||
return false;
|
||||
}
|
||||
this.wasmMemory = memory;
|
||||
const curPageCount = memory.buffer.byteLength >>> 16;
|
||||
const newPageCount = this.buf8.byteLength + PAGE_SIZE-1 >>> 16;
|
||||
const newPageCount = roundToPageSize(this.buf8.byteLength) >>> 16;
|
||||
if ( newPageCount > curPageCount ) {
|
||||
memory.grow(newPageCount - curPageCount);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue