aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-12-15 14:50:14 +1100
committerdaurnimator <quae@daurnimator.com>2017-12-15 14:53:03 +1100
commitb162ffe744bc407ad4035674f5c05848a460b58f (patch)
tree5d00c92294b3f562154104b269a5d6ca4d395c1e /src
parent55ff446d1fdd5ad5982e2ce3f7118fca8c16880b (diff)
downloadfengari-b162ffe744bc407ad4035674f5c05848a460b58f.tar.gz
fengari-b162ffe744bc407ad4035674f5c05848a460b58f.tar.bz2
fengari-b162ffe744bc407ad4035674f5c05848a460b58f.zip
src/lobject.js: Refactor luaO_chunkid to use Uint8Array.set
Diffstat (limited to 'src')
-rw-r--r--src/lobject.js26
-rw-r--r--src/luaconf.js2
2 files changed, 19 insertions, 9 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 5ca7cd3..c02bc91 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -294,7 +294,7 @@ class LocVar {
}
}
-const RETS = defs.to_luastring("...", true);
+const RETS = defs.to_luastring("...");
const PRE = defs.to_luastring("[string \"");
const POS = defs.to_luastring("\"]");
@@ -305,27 +305,37 @@ const luaO_chunkid = function(source, bufflen) {
if (l < bufflen) /* small enough? */
out = source.slice(1);
else { /* truncate it */
- out = source.slice(1, bufflen);
+ out = source.slice(1, bufflen+1);
}
} else if (source[0] === char['@']) { /* file name */
if (l <= bufflen) /* small enough? */
out = source.slice(1);
else { /* add '...' before rest of name */
+ out = new Uint8Array(bufflen);
+ out.set(RETS);
bufflen -= RETS.length;
- out = Uint8Array.from(Array.from(RETS).concat(Array.from(source.subarray(1 + l - bufflen))));
+ out.set(source.subarray(l - bufflen), RETS.length);
}
} else { /* string; format as [string "source"] */
+ out = new Uint8Array(bufflen);
let nli = source.indexOf(char['\n']); /* find first new line (if any) */
- out = Array.from(PRE); /* add prefix */
- bufflen -= PRE.length + RETS.length + POS.length + 1; /* save space for prefix+suffix+'\0' */
+ out.set(PRE); /* add prefix */
+ let out_i = PRE.length;
+ bufflen -= PRE.length + RETS.length + POS.length; /* save space for prefix+suffix */
if (l < bufflen && nli === -1) { /* small one-line source? */
- out = out.concat(Array.from(source), Array.from(POS)); /* keep it */
+ out.set(source, out_i); /* keep it */
+ out_i += source.length;
} else {
if (nli !== -1) l = nli; /* stop at first newline */
if (l > bufflen) l = bufflen;
- out = out.concat(Array.from(source.subarray(0, l)), Array.from(RETS), Array.from(POS));
+ out.set(source.subarray(0, l), out_i);
+ out_i += l;
+ out.set(RETS, out_i);
+ out_i += RETS.length;
}
- out = Uint8Array.from(out);
+ out.set(POS, out_i);
+ out_i += POS.length;
+ out = out.subarray(0, out_i);
}
return out;
};
diff --git a/src/luaconf.js b/src/luaconf.js
index 00663a6..5331720 100644
--- a/src/luaconf.js
+++ b/src/luaconf.js
@@ -19,7 +19,7 @@ const LUAI_MAXSTACK = 100000;
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
-const LUA_IDSIZE = 60;
+const LUA_IDSIZE = 60-1; /* fengari uses 1 less than lua as we don't embed the null byte */
const lua_integer2str = function(n) {
return sprintf(LUA_INTEGER_FMT, n);