From 56e3af1744e28d48f200c96c0dba428e1e3f2179 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 20 Jul 2019 11:25:52 -0300 Subject: [PATCH] Slightly improve performance of Channel:push(table). --- src/common/Variant.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/Variant.cpp b/src/common/Variant.cpp index 3a7ba1a11..0682e9f14 100644 --- a/src/common/Variant.cpp +++ b/src/common/Variant.cpp @@ -186,12 +186,13 @@ Variant Variant::fromLua(lua_State *L, int n, std::set *tableSet) case LUA_TTABLE: { bool success = true; - std::unique_ptr> tableSetPtr; + std::set topTableSet; std::vector> *table = new std::vector>(); - // If we had no tables argument, allocate one now, and store it in our unique_ptr + // We can use a pointer to a stack-allocated variable because it's + // never used after the stack-allocated variable is destroyed. if (tableSet == nullptr) - tableSetPtr.reset(tableSet = new std::set); + tableSet = &topTableSet; // Now make sure this table wasn't already serialised const void *tablePointer = lua_topointer(L, n);