diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-04-18 11:38:21 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-04-18 11:38:21 +0200 |
commit | 6be8db07196c407cd321a7b04f5022939c4ffce3 (patch) | |
tree | 1e979f818d2139a23a749d8536d8cc12b4858037 /src/lua.js | |
parent | 4f415e5ca594c5b60e6fa6315b69acb41273ee7e (diff) | |
download | fengari-6be8db07196c407cd321a7b04f5022939c4ffce3.tar.gz fengari-6be8db07196c407cd321a7b04f5022939c4ffce3.tar.bz2 fengari-6be8db07196c407cd321a7b04f5022939c4ffce3.zip |
Cache all to_luastring of internal literals
Diffstat (limited to 'src/lua.js')
-rw-r--r-- | src/lua.js | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -140,9 +140,16 @@ class lua_Debug { } -const to_luastring = function(str, maxBytesToWrite) { +const to_luastring_cache = {}; + +const to_luastring = function(str, cache, maxBytesToWrite) { assert(typeof str === "string", "to_luastring expect a js string"); + if (cache) { + let cached = to_luastring_cache[str]; + if (Array.isArray(cached)) return cached; + } + maxBytesToWrite = maxBytesToWrite !== undefined ? maxBytesToWrite : Number.MAX_SAFE_INTEGER; let outU8Array = []; @@ -195,6 +202,8 @@ const to_luastring = function(str, maxBytesToWrite) { } // Null-terminate the pointer to the buffer. // outU8Array[outIdx] = 0; + + if (cache) to_luastring_cache[str] = outU8Array; return outU8Array; }; |