summaryrefslogtreecommitdiff
path: root/src/lua.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-18 11:38:21 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-18 11:38:21 +0200
commit6be8db07196c407cd321a7b04f5022939c4ffce3 (patch)
tree1e979f818d2139a23a749d8536d8cc12b4858037 /src/lua.js
parent4f415e5ca594c5b60e6fa6315b69acb41273ee7e (diff)
downloadfengari-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.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lua.js b/src/lua.js
index 1423750..5175bfb 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -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;
};