summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2022-04-17 01:02:40 +0100
committerAlex Orlenko <zxteam@protonmail.com>2022-04-17 01:02:40 +0100
commit3904213ed078aa1263dd20eb9be5642180591c95 (patch)
tree3d974db01fe0d34319ee95d4d3d20e0b0973930e /src
parentdba76f3994e69b30cdcc2ca15517f344a48e61cf (diff)
downloadmlua-3904213ed078aa1263dd20eb9be5642180591c95.zip
Faster lua_rotate for Lua < 5.3
Diffstat (limited to 'src')
-rw-r--r--src/ffi/lua51/compat.rs7
-rw-r--r--src/ffi/lua52/compat.rs7
-rw-r--r--src/ffi/luau/compat.rs7
3 files changed, 21 insertions, 0 deletions
diff --git a/src/ffi/lua51/compat.rs b/src/ffi/lua51/compat.rs
index 892c507..9cd46fb 100644
--- a/src/ffi/lua51/compat.rs
+++ b/src/ffi/lua51/compat.rs
@@ -155,6 +155,13 @@ pub unsafe fn lua_absindex(L: *mut lua_State, mut idx: c_int) -> c_int {
pub unsafe fn lua_rotate(L: *mut lua_State, mut idx: c_int, mut n: c_int) {
idx = lua_absindex(L, idx);
+ if n > 0 {
+ // Faster version
+ for _ in 0..n {
+ lua_insert(L, idx);
+ }
+ return;
+ }
let n_elems = lua_gettop(L) - idx + 1;
if n < 0 {
n += n_elems;
diff --git a/src/ffi/lua52/compat.rs b/src/ffi/lua52/compat.rs
index 7ff962d..b834ab1 100644
--- a/src/ffi/lua52/compat.rs
+++ b/src/ffi/lua52/compat.rs
@@ -27,6 +27,13 @@ unsafe fn compat53_reverse(L: *mut lua_State, mut a: c_int, mut b: c_int) {
pub unsafe fn lua_rotate(L: *mut lua_State, mut idx: c_int, mut n: c_int) {
idx = lua_absindex(L, idx);
+ if n > 0 {
+ // Faster version
+ for _ in 0..n {
+ lua_insert(L, idx);
+ }
+ return;
+ }
let n_elems = lua_gettop(L) - idx + 1;
if n < 0 {
n += n_elems;
diff --git a/src/ffi/luau/compat.rs b/src/ffi/luau/compat.rs
index f92e858..eae4612 100644
--- a/src/ffi/luau/compat.rs
+++ b/src/ffi/luau/compat.rs
@@ -90,6 +90,13 @@ unsafe fn compat53_pushfuncname(L: *mut lua_State, level: c_int, ar: *mut lua_De
pub unsafe fn lua_rotate(L: *mut lua_State, mut idx: c_int, mut n: c_int) {
idx = lua_absindex(L, idx);
+ if n > 0 {
+ // Faster version
+ for _ in 0..n {
+ lua_insert(L, idx);
+ }
+ return;
+ }
let n_elems = lua_gettop(L) - idx + 1;
if n < 0 {
n += n_elems;