Skip to content

Commit bad2037

Browse files
committed
Simplify Table::clear method
There is no need to traverse array part, lua_next will cover everything
1 parent 40b507c commit bad2037

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/table.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,7 @@ impl Table {
416416

417417
lua.push_ref(&self.0);
418418

419-
// Clear array part
420-
for i in 1..=ffi::lua_rawlen(state, -1) {
421-
ffi::lua_pushnil(state);
422-
ffi::lua_rawseti(state, -2, i as Integer);
423-
}
424-
425-
// Clear hash part
426-
// It must be safe as long as we don't use invalid keys
419+
// This is safe as long as we don't assign new keys
427420
ffi::lua_pushnil(state);
428421
while ffi::lua_next(state, -2) != 0 {
429422
ffi::lua_pop(state, 1); // pop value

0 commit comments

Comments
 (0)