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

@@ -7,6 +7,6 @@ void DllExport LogWarning(lua_State* L, string message);
void DllExport LogError(lua_State* L, string message);
void DllExport Log(lua_State* L, string message, unsigned int level);
int DllExport dostring_in(lua_State* L, string target, string command);
map<unsigned int, json::value> DllExport getAllUnits(lua_State* L);
void DllExport getAllUnits(lua_State* L, map<unsigned int, json::value>& unitJSONs);
unsigned int DllExport TACANChannelToFrequency(unsigned int channel, char XY);

View File

@@ -56,10 +56,9 @@ void Log(lua_State* L, string message, unsigned int level)
STACK_CLEAN;
}
map<unsigned int, json::value> getAllUnits(lua_State* L)
void getAllUnits(lua_State* L, map<unsigned int, json::value>& unitJSONs)
{
unsigned int res = 0;
map<unsigned int, json::value> units;
STACK_INIT;
@@ -84,15 +83,16 @@ map<unsigned int, json::value> getAllUnits(lua_State* L)
while (lua_next(L, 2) != 0)
{
unsigned int ID = lua_tonumber(L, -2);
// TODO more efficient method can be used, converting all the lua data to a json object may be overkill
units[ID] = luaTableToJSON(L, -1);
if (unitJSONs.find(ID) == unitJSONs.end())
unitJSONs[ID] = json::value::object();
luaTableToJSON(L, -1, unitJSONs[ID]);
STACK_POP(1)
}
}
exit:
STACK_CLEAN;
return units;
return;
}
int dostring_in(lua_State* L, string target, string command)