From 1f53206abfbac6dcae709831f5070a99c23c19db Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 8 May 2017 16:50:55 +1000 Subject: src/lvm.js: Optimise luaV_concat Do the TString creation in one big Array.prototype.concat --- src/lvm.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src') 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 */ -- cgit v1.2.3-70-g09d2