From 7ea259e38b160bde34a071c5836f7a3b379aa062 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 14 Feb 2016 19:24:17 -0400 Subject: [PATCH] Optimize constructing a Variant from a Lua table with a non-zero array size. --- src/common/Variant.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/Variant.cpp b/src/common/Variant.cpp index 3426ed33e..2afc5c303 100644 --- a/src/common/Variant.cpp +++ b/src/common/Variant.cpp @@ -188,6 +188,10 @@ bool Variant::fromLua(lua_State *L, int n, Variant *v, bool allowTables) std::vector> *table = new std::vector>(); std::pair pair; + size_t len = luax_objlen(L, -1); + if (len > 0) + table->reserve(len); + lua_pushnil(L); while (lua_next(L, n))