aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-06 22:12:46 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-06 22:12:46 +1100
commit28f5e1052c7ee7fb15585621bd7c32ce72c02a82 (patch)
treedb8d8dcc520e237e4cb42ebb5da1d54361e00ed8 /src
parent46ac9a0d9511e4bcae87db547eee55f494833cbc (diff)
downloadfengari-28f5e1052c7ee7fb15585621bd7c32ce72c02a82.tar.gz
fengari-28f5e1052c7ee7fb15585621bd7c32ce72c02a82.tar.bz2
fengari-28f5e1052c7ee7fb15585621bd7c32ce72c02a82.zip
src/lauxlib.js: Use luaL_Buffer to implement luaL_gsub
Diffstat (limited to 'src')
-rw-r--r--src/lauxlib.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index f7988c4..7f491e1 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -570,14 +570,15 @@ const find_subarray = function(arr, subarr, from_index) {
const luaL_gsub = function(L, s, p, r) {
let wild;
- let b = [];
+ let b = new luaL_Buffer();
+ luaL_buffinit(L, b);
while ((wild = find_subarray(s, p)) >= 0) {
- b.push(...s.slice(0, wild)); /* push prefix */
- b.push(...r); /* push replacement in place of pattern */
- s = s.slice(wild + p.length); /* continue after 'p' */
+ luaL_addlstring(b, s, wild); /* push prefix */
+ luaL_addstring(b, r); /* push replacement in place of pattern */
+ s = s.subarray(wild + p.length); /* continue after 'p' */
}
- b.push(...s); /* push last suffix */
- lua.lua_pushstring(L, Uint8Array.from(b));
+ luaL_addstring(b, s); /* push last suffix */
+ luaL_pushresult(b);
return lua.lua_tostring(L, -1);
};