@assemblyscript/loader
Advanced tools
Comparing version 0.19.2 to 0.19.3
23
index.js
@@ -40,13 +40,20 @@ // Runtime header offsets | ||
const STRING_DECODE_THRESHOLD = 32; | ||
const decoder = new TextDecoder("utf-16le"); | ||
const STRING_SMALLSIZE = 192; // break-even point in V8 | ||
const STRING_CHUNKSIZE = 1024; // mitigate stack overflow | ||
const utf16 = new TextDecoder("utf-16le", { fatal: true }); // != wtf16 | ||
/** Gets a string from an U32 and an U16 view on a memory. */ | ||
/** Gets a string from memory. */ | ||
function getStringImpl(buffer, ptr) { | ||
const len = new Uint32Array(buffer)[ptr + SIZE_OFFSET >>> 2] >>> 1; | ||
const arr = new Uint16Array(buffer, ptr, len); | ||
if (len <= STRING_DECODE_THRESHOLD) { | ||
return String.fromCharCode.apply(String, arr); | ||
let len = new Uint32Array(buffer)[ptr + SIZE_OFFSET >>> 2] >>> 1; | ||
const wtf16 = new Uint16Array(buffer, ptr, len); | ||
if (len <= STRING_SMALLSIZE) return String.fromCharCode(...wtf16); | ||
try { | ||
return utf16.decode(wtf16); | ||
} catch { | ||
let str = "", off = 0; | ||
while (len - off > STRING_CHUNKSIZE) { | ||
str += String.fromCharCode(...wtf16.subarray(off, off += STRING_CHUNKSIZE)); | ||
} | ||
return str + String.fromCharCode(...wtf16.subarray(off)); | ||
} | ||
return decoder.decode(arr); | ||
} | ||
@@ -53,0 +60,0 @@ |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.19.2", | ||
"version": "0.19.3", | ||
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>", | ||
@@ -47,3 +47,6 @@ "license": "Apache-2.0", | ||
"README.md" | ||
] | ||
], | ||
"devDependencies": { | ||
"esm2umd": "^0.1.2" | ||
} | ||
} |
@@ -47,15 +47,29 @@ // GENERATED FILE. DO NOT EDIT. | ||
const THIS = Symbol(); | ||
const STRING_DECODE_THRESHOLD = 32; | ||
const decoder = new TextDecoder("utf-16le"); | ||
/** Gets a string from an U32 and an U16 view on a memory. */ | ||
const STRING_SMALLSIZE = 192; // break-even point in V8 | ||
const STRING_CHUNKSIZE = 1024; // mitigate stack overflow | ||
const utf16 = new TextDecoder("utf-16le", { | ||
fatal: true | ||
}); // != wtf16 | ||
/** Gets a string from memory. */ | ||
function getStringImpl(buffer, ptr) { | ||
const len = new Uint32Array(buffer)[ptr + SIZE_OFFSET >>> 2] >>> 1; | ||
const arr = new Uint16Array(buffer, ptr, len); | ||
let len = new Uint32Array(buffer)[ptr + SIZE_OFFSET >>> 2] >>> 1; | ||
const wtf16 = new Uint16Array(buffer, ptr, len); | ||
if (len <= STRING_SMALLSIZE) return String.fromCharCode(...wtf16); | ||
if (len <= STRING_DECODE_THRESHOLD) { | ||
return String.fromCharCode.apply(String, arr); | ||
try { | ||
return utf16.decode(wtf16); | ||
} catch { | ||
let str = "", | ||
off = 0; | ||
while (len - off > STRING_CHUNKSIZE) { | ||
str += String.fromCharCode(...wtf16.subarray(off, off += STRING_CHUNKSIZE)); | ||
} | ||
return str + String.fromCharCode(...wtf16.subarray(off)); | ||
} | ||
return decoder.decode(arr); | ||
} | ||
@@ -62,0 +76,0 @@ /** Prepares the base module prior to instantiation. */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41485
931
1