From 7e886ba08a443d9653c3033901ae8c83108d3701 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 21:17:26 +1000 Subject: src/lapi.js: Simplify+optimise lua_rotate --- src/lapi.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lapi.js b/src/lapi.js index ca5a8a0..f06fc65 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -181,14 +181,14 @@ const reverse = function(L, from, to) { ** rotate x n === BA. But BA === (A^r . B^r)^r. */ const lua_rotate = function(L, idx, n) { - let t = L.stack[L.top - 1]; - let p = index2addr(L, idx); + let t = L.top - 1; let pIdx = index2addr_(L, idx); + let p = L.stack[pIdx]; - assert(p !== lobject.luaO_nilobject && idx > defs.LUA_REGISTRYINDEX, "index not in the stack"); - assert((n >= 0 ? n : -n) <= (L.top - idx), "invalid 'n'"); + assert(isvalid(p) && idx > defs.LUA_REGISTRYINDEX, "index not in the stack"); + assert((n >= 0 ? n : -n) <= (t - pIdx + 1), "invalid 'n'"); - let m = n >= 0 ? L.top - 1 - n : pIdx - n - 1; /* end of prefix */ + let m = n >= 0 ? t - n : pIdx - n - 1; /* end of prefix */ reverse(L, pIdx, m); reverse(L, m + 1, L.top - 1); -- cgit v1.2.3-70-g09d2