From 11a2421acaf2b39d19ee99933102c35e28fd13f8 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 13 Dec 2017 14:55:33 +1100 Subject: Use Uint8Array to back strings --- src/loslib.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/loslib.js') diff --git a/src/loslib.js b/src/loslib.js index 19dfd02..f27a7ed 100644 --- a/src/loslib.js +++ b/src/loslib.js @@ -73,7 +73,7 @@ const checkoption = function(L, conv, i, buff) { if (option[o] === '|'.charCodeAt(0)) /* next block? */ oplen++; /* will check options with next length (+1) */ else if (array_cmp(conv, i, option, o, oplen)) { /* match? */ - buff.push(...conv.slice(i, i+oplen)); /* copy valid option to buffer */ + buff.set(conv.slice(i, i+oplen)); /* copy valid option to buffer */ return i + oplen; /* return next item */ } } @@ -102,6 +102,8 @@ const os_date = function(L) { lua.lua_createtable(L, 0, 9); /* 9 = number of fields */ setallfields(L, stm, utc); } else { + let cc = new Uint8Array(4); + cc[0] = "%".charCodeAt(0); let b = new lauxlib.luaL_Buffer(); lauxlib.luaL_buffinit(L, b); while (i < s.length) { @@ -109,8 +111,10 @@ const os_date = function(L) { lauxlib.luaL_addchar(b, s[i++]); } else { i++; /* skip '%' */ - let cc = ["%".charCodeAt(0)]; - i = checkoption(L, s, i, cc); /* copy specifier to 'cc' */ + i = checkoption(L, s, i, cc.subarray(1)); /* copy specifier to 'cc' */ + let len = cc.indexOf(0); + if (len !== -1) + cc = cc.subarray(0, len); let buff = strftime(lua.to_jsstring(cc), stm); lauxlib.luaL_addstring(b, lua.to_luastring(buff)); } -- cgit v1.2.3-54-g00ecf