diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-30 18:35:54 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-30 18:36:12 +0100 |
commit | bc291713c56a2bc27ec10cef52dd3a52a0579c7d (patch) | |
tree | 4ad966892dedd54ecdbde5e79abb57c6d33f62f1 /src | |
parent | c41269058f2e9b2d612099ac97fa7a74a38bd584 (diff) | |
download | manaserv-bc291713c56a2bc27ec10cef52dd3a52a0579c7d.tar.gz manaserv-bc291713c56a2bc27ec10cef52dd3a52a0579c7d.tar.bz2 manaserv-bc291713c56a2bc27ec10cef52dd3a52a0579c7d.tar.xz manaserv-bc291713c56a2bc27ec10cef52dd3a52a0579c7d.zip |
Fixed some lua_newtable/createtable usage
When creating a Lua table, it is possible to specify in advance how many
array elements and how many non-array elements this table will contain,
to avoid dynamic reallocations while filling the table. This wasn't used
optimally by the pushSTLContainer helper methods and some other cases.
Reviewed-by: Erik Schilling
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src')
-rw-r--r-- | src/scripting/lua.cpp | 4 | ||||
-rw-r--r-- | src/scripting/luautil.h | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index eb50f168..c7053b3c 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -386,7 +386,7 @@ static int chr_get_inventory(lua_State *s) lua_pushinteger(s, tableIndex); // Create the sub-table (value of the main one) - lua_newtable(s); + lua_createtable(s, 0, 4); int subTableStackPosition = lua_gettop(s); // Stores the item info in it. lua_pushstring(s, "slot"); @@ -458,7 +458,7 @@ static int chr_get_equipment(lua_State *s) lua_pushinteger(s, tableIndex); // Create the sub-table (value of the main one) - lua_newtable(s); + lua_createtable(s, 0, 3); int subTableStackPosition = lua_gettop(s); // Stores the item info in it. lua_pushstring(s, "slot"); diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h index 82bb78cf..ee3f1142 100644 --- a/src/scripting/luautil.h +++ b/src/scripting/luautil.h @@ -63,7 +63,7 @@ void push(lua_State *s, MapObject *val); template <typename T> void pushSTLContainer(lua_State *s, const std::list<T> &container) { int len = container.size(); - lua_newtable(s); + lua_createtable(s, len, 0); int table = lua_gettop(s); typename std::list<T>::const_iterator i; i = container.begin(); @@ -81,7 +81,7 @@ template <typename T> void pushSTLContainer(lua_State *s, const std::list<T> &co template <typename T> void pushSTLContainer(lua_State *s, const std::vector<T> &container) { int len = container.size(); - lua_createtable(s, 0, len); + lua_createtable(s, len, 0); int table = lua_gettop(s); for (int key = 0; key < len; key++) @@ -114,7 +114,7 @@ template <typename Tkey, typename Tval> void pushSTLContainer(lua_State *s, cons template <typename T> void pushSTLContainer(lua_State *s, const std::set<T> &container) { int len = container.size(); - lua_newtable(s); + lua_createtable(s, len, 0); int table = lua_gettop(s); typename std::set<T>::const_iterator i; i = container.begin(); |