Skip to content

Commit 11a9054

Browse files
committed
player/lua: pre-allocate tables of known size
1 parent 7ff087a commit 11a9054

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

player/lua.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ static void pushnode(lua_State *L, mpv_node *node)
898898
lua_pushboolean(L, node->u.flag);
899899
break;
900900
case MPV_FORMAT_NODE_ARRAY:
901-
lua_newtable(L); // table
901+
lua_createtable(L, node->u.list->num, 0); // table
902902
lua_getfield(L, LUA_REGISTRYINDEX, "ARRAY"); // table mt
903903
lua_setmetatable(L, -2); // table
904904
for (int n = 0; n < node->u.list->num; n++) {
@@ -907,7 +907,7 @@ static void pushnode(lua_State *L, mpv_node *node)
907907
}
908908
break;
909909
case MPV_FORMAT_NODE_MAP:
910-
lua_newtable(L); // table
910+
lua_createtable(L, 0, node->u.list->num); // table
911911
lua_getfield(L, LUA_REGISTRYINDEX, "MAP"); // table mt
912912
lua_setmetatable(L, -2); // table
913913
for (int n = 0; n < node->u.list->num; n++) {

0 commit comments

Comments
 (0)