diff options
author | stephan <stephan@noemail.net> | 2022-12-06 08:21:23 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-06 08:21:23 +0000 |
commit | b849832a79271c8743ddcd455d6bfcaca88433d0 (patch) | |
tree | 80dd46cc414c0b054a83feccd18a79553eb37ab9 /ext/wasm/common/whwasmutil.js | |
parent | f2bbef39516f9f26e1f107a21de4e24e24551327 (diff) | |
download | sqlite-b849832a79271c8743ddcd455d6bfcaca88433d0.tar.gz sqlite-b849832a79271c8743ddcd455d6bfcaca88433d0.zip |
Minor internal JS code/docs cleanups.
FossilOrigin-Name: 21331bdd36a91b07a687ffadce392dcf2ccd0fd824b35d9dd027d4289a40fc96
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r-- | ext/wasm/common/whwasmutil.js | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 9bce82f1a..ea344c6ea 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -943,10 +943,19 @@ self.WhWasmUtilInstaller = function(target){ const __allocCStr = function(jstr, returnWithLength, allocator, funcName){ __affirmAlloc(target, funcName); if('string'!==typeof jstr) return null; - const n = target.jstrlen(jstr), - ptr = allocator(n+1); - target.jstrcpy(jstr, target.heap8u(), ptr, n+1, true); - return returnWithLength ? [ptr, n] : ptr; + if(0){/* older impl, possibly more widely compatible? */ + const n = target.jstrlen(jstr), + ptr = allocator(n+1); + target.jstrcpy(jstr, target.heap8u(), ptr, n+1, true); + return returnWithLength ? [ptr, n] : ptr; + }else{/* newer, (probably) faster and (certainly) simpler impl */ + const u = cache.utf8Encoder.encode(jstr), + ptr = allocator(u.length+1), + heap = heapWrappers().HEAP8U; + heap.set(u, ptr); + heap[ptr + u.length] = 0; + return returnWithLength ? [ptr, u.length] : ptr; + } }; /** |