diff options
| author | 2016-07-31 20:45:22 -0400 | |
|---|---|---|
| committer | 2016-08-03 02:32:22 -0400 | |
| commit | 7d08b0c3d7e1d4450bcb8a96abc7518c5a115917 (patch) | |
| tree | 82c407f0ce531cc4c2fe2a82ed45bb2b171f5251 /src/modules/window | |
| parent | KviMenubar: ensure Actions entry has an Icon at least. (diff) | |
| download | KVIrc-7d08b0c3d7e1d4450bcb8a96abc7518c5a115917.tar.gz KVIrc-7d08b0c3d7e1d4450bcb8a96abc7518c5a115917.tar.bz2 KVIrc-7d08b0c3d7e1d4450bcb8a96abc7518c5a115917.zip | |
Part 1: Bring KVIrc to the 21st century
Avoid many un-necessary memory allocations as well as start
the migration to unique pointers where appropriate.
Start migrating out of the KVirc standard library into the C++ standard
library.
Diffstat (limited to 'src/modules/window')
| -rw-r--r-- | src/modules/window/UserWindow.cpp | 9 | ||||
| -rw-r--r-- | src/modules/window/libkviwindow.cpp | 64 |
2 files changed, 33 insertions, 40 deletions
diff --git a/src/modules/window/UserWindow.cpp b/src/modules/window/UserWindow.cpp index 48d34c734..e1d7500ab 100644 --- a/src/modules/window/UserWindow.cpp +++ b/src/modules/window/UserWindow.cpp @@ -28,12 +28,15 @@ #include "KviMainWindow.h" #include "KviConsoleWindow.h" -extern KviPointerList<UserWindow> * g_pUserWindowList; +#include <algorithm> +#include <map> + +extern std::vector<UserWindow *> g_pUserWindowList; UserWindow::UserWindow(const char * pcName, QString & szIcon, KviConsoleWindow * pConsole, int iCreationFlags) : KviWindow(KviWindow::UserWindow, pcName, pConsole) { - g_pUserWindowList->append(this); + g_pUserWindowList.push_back(this); m_szIcon = szIcon; @@ -55,7 +58,7 @@ UserWindow::~UserWindow() { if(context()) context()->unregisterContextWindow(this); - g_pUserWindowList->removeRef(this); + g_pUserWindowList.erase(std::remove(g_pUserWindowList.begin(), g_pUserWindowList.end(), this), g_pUserWindowList.end()); } QPixmap * UserWindow::myIconPtr() diff --git a/src/modules/window/libkviwindow.cpp b/src/modules/window/libkviwindow.cpp index ea690f02a..cb7e4be88 100644 --- a/src/modules/window/libkviwindow.cpp +++ b/src/modules/window/libkviwindow.cpp @@ -38,9 +38,10 @@ #include "KviModuleManager.h" #include "KviMemory.h" #include "KviChannelWindow.h" -#include "KviPointerHashTable.h" #include <QTimer> +#include <map> +#include <vector> #ifdef COMPILE_CRYPT_SUPPORT #include "KviCryptEngine.h" @@ -50,8 +51,8 @@ extern KVIRC_API KviCryptEngineManager * g_pCryptEngineManager; #endif // KviApplication.cpp -extern KVIRC_API KviPointerHashTable<QString, KviWindow> * g_pGlobalWindowDict; -KviPointerList<UserWindow> * g_pUserWindowList = nullptr; +extern KVIRC_API std::map<QString, KviWindow *> g_pGlobalWindowDict; +std::vector<UserWindow *> g_pUserWindowList; // $window.caption $window.x $window.y $window.width $window.height $window.isActive $window.type // $window.input.text $window.input.cursorpos $window.input.textlen @@ -841,78 +842,72 @@ static bool window_kvs_fnc_list(KviKvsModuleFunctionCall * c) { // all contexts but no "no_context" windows bool bAllWindows = KviQString::equalCI(szType, "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - if(wnd->context()) + if(wnd.second->context()) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } } - ++it; } } else if(KviQString::equalCI(szContext, "any")) { // all contexts and also "no_context" windows bool bAllWindows = KviQString::equalCI(szType.toLower(), "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } - ++it; } } else if(KviQString::equalCI(szContext, "none")) { // only "no_context" windows bool bAllWindows = KviQString::equalCI(szType.toLower(), "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - if(!wnd->context()) + if(!wnd.second->context()) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } } - ++it; } } else @@ -942,30 +937,28 @@ static bool window_kvs_fnc_list(KviKvsModuleFunctionCall * c) } bool bAllWindows = KviQString::equalCI(szType.toLower(), "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - if(wnd->context()) + if(wnd.second->context()) { - if(wnd->context()->id() == uId) + if(wnd.second->context()->id() == uId) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } } } - ++it; } } return true; @@ -1505,9 +1498,6 @@ static bool window_kvs_cmd_fake(KviKvsModuleCommandCall * c) static bool window_module_init(KviModule * m) { - g_pUserWindowList = new KviPointerList<UserWindow>(); - g_pUserWindowList->setAutoDelete(false); - KVSM_REGISTER_FUNCTION(m, "activityTemperature", window_kvs_fnc_activityTemperature); KVSM_REGISTER_FUNCTION(m, "activityLevel", window_kvs_fnc_activityLevel); KVSM_REGISTER_FUNCTION(m, "highlightLevel", window_kvs_fnc_highlightLevel); @@ -1550,15 +1540,15 @@ static bool window_module_init(KviModule * m) static bool window_module_cleanup(KviModule *) { - while(UserWindow * w = g_pUserWindowList->first()) + for(auto & w : g_pUserWindowList) w->close(); - delete g_pUserWindowList; + g_pUserWindowList.clear(); return true; } static bool window_module_can_unload(KviModule *) { - return g_pUserWindowList->isEmpty(); + return g_pUserWindowList.empty(); } KVIRC_MODULE( |
