From 5b564fb8e230f98b672aea534c16d7d99ffe1944 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 11 Dec 2017 15:45:34 +1100 Subject: src/lapi.js: Keep empty string constant around --- src/lapi.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index 2ae5b3c..0c1a3a6 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -230,15 +230,18 @@ const lua_pushinteger = function(L, n) { assert(L.top <= L.ci.top, "stack overflow"); }; +const emptystring = []; + const lua_pushlstring = function(L, s, len) { assert(typeof len === "number"); let ts; if (len === 0) { - ts = lstring.luaS_bless(L, []); + s = emptystring; } else { assert(defs.is_luastring(s) && s.length >= len, "lua_pushlstring expects array of byte"); - ts = lstring.luaS_bless(L, s.slice(0, len)); + s = s.slice(0, len); } + ts = lstring.luaS_bless(L, s); lobject.pushsvalue2s(L, ts); assert(L.top <= L.ci.top, "stack overflow"); @@ -1055,7 +1058,7 @@ const lua_concat = function(L, n) { if (n >= 2) lvm.luaV_concat(L, n); else if (n === 0) { - lobject.pushsvalue2s(L, lstring.luaS_bless(L, [])); + lobject.pushsvalue2s(L, lstring.luaS_bless(L, emptystring)); assert(L.top <= L.ci.top, "stack overflow"); } }; -- cgit v1.2.3-70-g09d2