Performance optimizations for large unit counts

This commit is contained in:
Pax1601
2023-07-18 21:56:56 +02:00
parent 785647ad24
commit a4db569fbd
43 changed files with 1188 additions and 580 deletions

View File

@@ -4,7 +4,7 @@
void DllExport stackUpdate(lua_State* L, int& stackDepth, int initialStack = 0);
void DllExport stackPop(lua_State* L, int popDepth = 1);
void DllExport stackClean(lua_State* L, int stackDepth);
json::value DllExport luaTableToJSON(lua_State* L, int index, bool logKeys = false);
void DllExport luaTableToJSON(lua_State* L, int index, json::value& json, bool logKeys = false);
#define STACK_UPDATE stackUpdate(L, stackDepth, initialStack);
#define STACK_INIT int stackDepth = 0; int initialStack = 0; stackUpdate(L, initialStack);

View File

@@ -18,10 +18,8 @@ void stackClean(lua_State* L, int stackDepth)
lua_pop(L, stackDepth);
}
json::value luaTableToJSON(lua_State* L, int index, bool logKeys)
void luaTableToJSON(lua_State* L, int index, json::value& json, bool logKeys)
{
auto json = json::value::object();
if (lua_istable(L, index))
{
STACK_INIT;
@@ -38,7 +36,9 @@ json::value luaTableToJSON(lua_State* L, int index, bool logKeys)
}
if (lua_istable(L, -2))
{
json[to_wstring(key)] = luaTableToJSON(L, -2, logKeys);
if (!json.has_object_field(to_wstring(key)))
json[to_wstring(key)] = json::value::object();
luaTableToJSON(L, -2, json[to_wstring(key)], logKeys);
}
else if (lua_isnumber(L, -2))
{
@@ -58,6 +58,5 @@ json::value luaTableToJSON(lua_State* L, int index, bool logKeys)
STACK_CLEAN;
}
return json;
}