summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-08 16:50:55 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-08 16:57:59 +1000
commit1f53206abfbac6dcae709831f5070a99c23c19db (patch)
treec365a159c78d914027b3040591c4a8f69c999670
parente67fb5f4cb51fbf4061ab647ef08ef4893b7f0e4 (diff)
downloadfengari-1f53206abfbac6dcae709831f5070a99c23c19db.tar.gz
fengari-1f53206abfbac6dcae709831f5070a99c23c19db.tar.bz2
fengari-1f53206abfbac6dcae709831f5070a99c23c19db.zip
src/lvm.js: Optimise luaV_concat
Do the TString creation in one big Array.prototype.concat
-rw-r--r--src/lvm.js17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/lvm.js b/src/lvm.js
index 03b7e3c..15081ad 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -1021,20 +1021,13 @@ const luaV_concat = function(L, total) {
L.stack[top - 2] = L.stack[top - 1];
} else {
/* at least two non-empty string values; get as many as possible */
- let tl = L.stack[top-1].vslen();
- /* collect total length and number of strings */
+ let toconcat = new Array(total);
+ toconcat[total-1] = L.stack[top-1].svalue();
for (n = 1; n < total && tostring(L, top - n - 1); n++) {
- let l = L.stack[top - n - 1].vslen();
- // TODO: string length overflow ?
- tl += l;
+ toconcat[total-n-1] = L.stack[top - n - 1].svalue();
}
-
- let ts = [];
- for (let i = n; i > 0; i--) {
- ts = ts.concat(L.stack[top - i].svalue());
- }
-
- L.stack[top - n] = new lobject.TValue(CT.LUA_TLNGSTR, lstring.luaS_bless(L, ts));
+ let ts = lstring.luaS_bless(L, Array.prototype.concat.apply([], toconcat));
+ L.stack[top - total] = new lobject.TValue(CT.LUA_TLNGSTR, ts);
}
total -= n - 1; /* got 'n' strings to create 1 new */
L.top -= n - 1; /* popped 'n' strings and pushed one */