mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
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 ( typeof WebAssembly !== 'object' ) { return false; }
|
||||||
if ( this.wasmMemory instanceof WebAssembly.Memory ) { return true; }
|
if ( this.wasmMemory instanceof WebAssembly.Memory ) { return true; }
|
||||||
const module = await getWasmModule();
|
const module = await getWasmModule();
|
||||||
if ( module instanceof WebAssembly.Module === false ) {
|
if ( module instanceof WebAssembly.Module === false ) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const memory = new WebAssembly.Memory({ initial: 2 });
|
const memory = new WebAssembly.Memory({ initial: 2 });
|
||||||
const instance = await WebAssembly.instantiate(
|
const instance = await WebAssembly.instantiate(module, {
|
||||||
module,
|
imports: {
|
||||||
{
|
memory,
|
||||||
imports: {
|
growBuf: this.growBuf.bind(this, 24, 256)
|
||||||
memory,
|
|
||||||
growBuf: this.growBuf.bind(this, 24, 256)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
if ( instance instanceof WebAssembly.Instance === false ) {
|
if ( instance instanceof WebAssembly.Instance === false ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.wasmMemory = memory;
|
this.wasmMemory = memory;
|
||||||
const curPageCount = memory.buffer.byteLength >>> 16;
|
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 ) {
|
if ( newPageCount > curPageCount ) {
|
||||||
memory.grow(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 ( typeof WebAssembly !== 'object' ) { return false; }
|
||||||
if ( this.wasmMemory instanceof WebAssembly.Memory ) { return true; }
|
if ( this.wasmMemory instanceof WebAssembly.Memory ) { return true; }
|
||||||
const module = await getWasmModule();
|
const module = await getWasmModule();
|
||||||
if ( module instanceof WebAssembly.Module === false ) {
|
if ( module instanceof WebAssembly.Module === false ) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const memory = new WebAssembly.Memory({
|
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 ) {
|
if ( instance instanceof WebAssembly.Instance === false ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.wasmMemory = memory;
|
this.wasmMemory = memory;
|
||||||
const curPageCount = memory.buffer.byteLength >>> 16;
|
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 ) {
|
if ( newPageCount > curPageCount ) {
|
||||||
memory.grow(newPageCount - curPageCount);
|
memory.grow(newPageCount - curPageCount);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user