From b01bf7ef940503e373d59c912c9952582a608a77 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 9 Jun 2017 15:25:05 +1000 Subject: src/lzio.js: Introduce luaZ_resetbuffer --- src/llex.js | 15 ++++----------- src/lzio.js | 16 +++++++++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/llex.js b/src/llex.js index 4c2be8c..c110a7a 100644 --- a/src/llex.js +++ b/src/llex.js @@ -320,10 +320,7 @@ const read_long_string = function(ls, seminfo, sep) { case char['\n']: case char['\r']: { save(ls, char['\n']); inclinenumber(ls); - if (!seminfo) { - ls.buff.n = 0; - ls.buff.buffer = []; - } + if (!seminfo) lzio.luaZ_resetbuffer(ls.buff); break; } default: { @@ -468,9 +465,7 @@ const isreserved = function(w) { }; const llex = function(ls, seminfo) { - ls.buff.n = 0; - ls.buff.buffer = []; - + lzio.luaZ_resetbuffer(ls.buff); for (;;) { assert(typeof ls.current == "number"); switch (ls.current) { @@ -489,12 +484,10 @@ const llex = function(ls, seminfo) { next(ls); if (ls.current === char['[']) { /* long comment? */ let sep = skip_sep(ls); - ls.buff.n = 0; /* 'skip_sep' may dirty the buffer */ - ls.buff.buffer = []; + lzio.luaZ_resetbuffer(ls.buff); /* 'skip_sep' may dirty the buffer */ if (sep >= 0) { read_long_string(ls, null, sep); /* skip long comment */ - ls.buff.n = 0; /* previous call may dirty the buff. */ - ls.buff.buffer = []; + lzio.luaZ_resetbuffer(ls.buff); /* previous call may dirty the buff. */ break; } } diff --git a/src/lzio.js b/src/lzio.js index 919ed44..72969d4 100644 --- a/src/lzio.js +++ b/src/lzio.js @@ -10,6 +10,11 @@ class MBuffer { } } +const luaZ_resetbuffer = function(buff) { + buff.n = 0; + buff.buffer = []; +}; + class ZIO { constructor(L, reader, data) { this.L = L; /* Lua state (for reader) */ @@ -74,8 +79,9 @@ const luaZ_read = function(z, b, b_offset, n) { return 0; }; -module.exports.EOZ = EOZ; -module.exports.luaZ_fill = luaZ_fill; -module.exports.luaZ_read = luaZ_read; -module.exports.MBuffer = MBuffer; -module.exports.ZIO = ZIO; +module.exports.EOZ = EOZ; +module.exports.luaZ_fill = luaZ_fill; +module.exports.luaZ_read = luaZ_read; +module.exports.luaZ_resetbuffer = luaZ_resetbuffer; +module.exports.MBuffer = MBuffer; +module.exports.ZIO = ZIO; -- cgit v1.2.3-70-g09d2