aboutsummaryrefslogtreecommitdiff
path: root/src/loslib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-12-13 14:55:33 +1100
committerdaurnimator <quae@daurnimator.com>2017-12-13 15:31:04 +1100
commit11a2421acaf2b39d19ee99933102c35e28fd13f8 (patch)
tree4abd1fa6ee063f75c634349a02702de7bc145a8b /src/loslib.js
parent3e7c102eefbaae9e6bc839b11bba79aee1c5e040 (diff)
downloadfengari-11a2421acaf2b39d19ee99933102c35e28fd13f8.tar.gz
fengari-11a2421acaf2b39d19ee99933102c35e28fd13f8.tar.bz2
fengari-11a2421acaf2b39d19ee99933102c35e28fd13f8.zip
Use Uint8Array to back strings
Diffstat (limited to 'src/loslib.js')
-rw-r--r--src/loslib.js10
1 files changed, 7 insertions, 3 deletions
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));
}