Skip to content

Commit

Permalink
Use lua_createtable instead of lua_newtable
Browse files Browse the repository at this point in the history
Allows preallocating the needed size for its elements since they're known in advance
  • Loading branch information
edo9300 committed Dec 8, 2023
1 parent e794a31 commit cdb14fd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ LUA_FUNCTION(GetCounter) {
}
LUA_FUNCTION(GetAllCounters) {
check_param_count(L, 1);
lua_newtable(L);
lua_createtable(L, self->counters.size(), 0);
for(const auto& counter : self->counters) {
lua_pushinteger(L, counter.first);
lua_pushinteger(L, counter.second[0] + counter.second[1]);
Expand Down
2 changes: 1 addition & 1 deletion libduel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,7 @@ LUA_STATIC_FUNCTION(SelectCardsFromCodes) {
luaL_checkstack(L, static_cast<int>(ret_codes.list.size() + (3 * ret_index) /* account for table creation */), nullptr);
for(const auto& obj : ret_codes.list) {
if(ret_index) {
lua_newtable(L);
lua_createtable(L, 2, 0);
lua_pushinteger(L, 1);
}
lua_pushinteger(L, obj.first);
Expand Down
2 changes: 1 addition & 1 deletion libgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ LUA_FUNCTION(GetClass) {
for(auto& pcard : self->container) {
er.insert(pduel->lua->get_operation_value(pcard, findex, extraargs));
}
lua_newtable(L);
lua_createtable(L, er.size(), 0);
int i = 1;
for(auto& val : er) {
lua_pushinteger(L, i++);
Expand Down

0 comments on commit cdb14fd

Please sign in to comment.