aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-22 21:17:26 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 21:17:26 +1000
commit7e886ba08a443d9653c3033901ae8c83108d3701 (patch)
treedaa830621ed1a014e8190df5bfd4ba2eabbf9e1e /src
parent25e2110a5eac0a2e6c7b4d502ffbd53fc61af301 (diff)
downloadfengari-7e886ba08a443d9653c3033901ae8c83108d3701.tar.gz
fengari-7e886ba08a443d9653c3033901ae8c83108d3701.tar.bz2
fengari-7e886ba08a443d9653c3033901ae8c83108d3701.zip
src/lapi.js: Simplify+optimise lua_rotate
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js10
1 files 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);