From bad20374ad95b43270d2fa4f8ea0e8ddee7ba1d7 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Mon, 8 Sep 2025 23:09:26 +0100 Subject: [PATCH] Simplify `Table::clear` method There is no need to traverse array part, lua_next will cover everything --- src/table.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/table.rs b/src/table.rs index b182a6c..91b6e8e 100644 --- a/src/table.rs +++ b/src/table.rs @@ -416,14 +416,7 @@ impl Table { lua.push_ref(&self.0); - // Clear array part - for i in 1..=ffi::lua_rawlen(state, -1) { - ffi::lua_pushnil(state); - ffi::lua_rawseti(state, -2, i as Integer); - } - - // Clear hash part - // It must be safe as long as we don't use invalid keys + // This is safe as long as we don't assign new keys ffi::lua_pushnil(state); while ffi::lua_next(state, -2) != 0 { ffi::lua_pop(state, 1); // pop value