# HG changeset patch # User Santeri Piippo # Date 1369152458 -10800 # Node ID ea09eeba1c2b2ae088857f0dc64199c9043912d7 # Parent 3b35f502a6c75a4881d6124b8b200863da4525d5 Use a C-array for config too for the same reasons as with actions diff -r 3b35f502a6c7 -r ea09eeba1c2b src/config.cpp --- a/src/config.cpp Tue May 21 18:56:38 2013 +0300 +++ b/src/config.cpp Tue May 21 19:07:38 2013 +0300 @@ -24,7 +24,8 @@ #include "misc.h" #include "gui.h" -std::vector g_configPointers; +config* g_configPointers[MAX_CONFIG]; +static ushort g_cfgPointerCursor = 0; // ============================================================================= const char* g_WeekdayNames[7] = { @@ -101,9 +102,13 @@ // Find the config entry for this. config* cfg = null; - for (config* i : g_configPointers) + for (config* i : g_configPointers) { + if (!i) + break; + if (entry == i->name) cfg = i; + } if (!cfg) { fprintf (stderr, "unknown config `%s`\n", entry.chars()); @@ -211,6 +216,9 @@ timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); for (config* cfg : g_configPointers) { + if (!cfg) + break; + str valstring; switch (cfg->getType()) { case CONFIG_int: @@ -251,8 +259,12 @@ // ============================================================================= void config::reset () { - for (size_t i = 0; i < NUM_CONFIG; i++) - g_configPointers[i]->resetValue (); + for (config* cfg : g_configPointers) { + if (!cfg) + break; + + cfg->resetValue (); + } } // ============================================================================= @@ -272,4 +284,12 @@ #else return fmt ("%s" DIRSLASH APPNAME DIRSLASH, qchars (QDir::homePath ())); #endif // _WIN32 +} + +void addConfig (config* ptr) { + if (g_cfgPointerCursor == 0) + memset (g_configPointers, 0, sizeof g_configPointers); + + assert (g_cfgPointerCursor < MAX_CONFIG); + g_configPointers[g_cfgPointerCursor++] = ptr; } \ No newline at end of file diff -r 3b35f502a6c7 -r ea09eeba1c2b src/config.h --- a/src/config.h Tue May 21 18:56:38 2013 +0300 +++ b/src/config.h Tue May 21 19:07:38 2013 +0300 @@ -26,7 +26,7 @@ #include #define MAX_INI_LINE 512 -#define NUM_CONFIG (g_configPointers.size ()) +#define MAX_CONFIG 512 #define cfg(T, NAME, DEFAULT) \ T##config NAME (DEFAULT, #NAME, #T, #DEFAULT) @@ -63,7 +63,7 @@ static str filepath (); }; -extern std::vector g_configPointers; +void addConfig (config* ptr); // ============================================================================= #define DEFINE_UNARY_OPERATOR(T, OP) \ @@ -118,7 +118,7 @@ name = _name; \ typestring = _typestring; \ defaultstring = _defaultstring; \ - g_configPointers.push_back (this); \ + addConfig (this); \ } \ operator T () { \ return value; \