diff --git a/src/sqlite-api.js b/src/sqlite-api.js index 2883bc47..2b3c04f7 100644 --- a/src/sqlite-api.js +++ b/src/sqlite-api.js @@ -34,11 +34,12 @@ export function Factory(Module) { const tmp = Module._malloc(8); const tmpPtr = [tmp, tmp + 4]; + const textEncoder = new TextEncoder(); // Convert a JS string to a C string. sqlite3_malloc is used to allocate // memory (use sqlite3_free to deallocate). function createUTF8(s) { if (typeof s !== 'string') return 0; - const utf8 = new TextEncoder().encode(s); + const utf8 = textEncoder.encode(s); const zts = Module._sqlite3_malloc(utf8.byteLength + 1); Module.HEAPU8.set(utf8, zts); Module.HEAPU8[zts + utf8.byteLength] = 0; @@ -661,7 +662,7 @@ export function Factory(Module) { const onFinally = []; try { // Encode SQL string to UTF-8. - const utf8 = new TextEncoder().encode(sql); + const utf8 = textEncoder.encode(sql); // Copy encoded string to WebAssembly memory. The SQLite docs say // zero-termination is a minor optimization so add room for that.