From 0b92a66c50974548e276bb89ed76c5ef6c5edf43 Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 12 Dec 2019 17:31:22 +0000 Subject: [PATCH] Replace list of hwnd -> IrrlichtDevice mapper with an array. Single inserts/removes per device creating/destruction, but searchs on every event. Arrays are better for that than lists. Also document a bit. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6004 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CIrrDeviceWin32.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index d8277554..a3a29c88 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -677,13 +677,13 @@ static unsigned int LocaleIdToCodepage(unsigned int lcid) namespace { - // TODO: Why do we have a list here? Seems like it can only ever be one. Unfortunately code is older than svn log, so not sure about origins of this. struct SEnvMapper { HWND hWnd; irr::CIrrDeviceWin32* irrDev; }; - irr::core::list EnvMap; + // NOTE: This is global. We can have more than one Irrlicht Device at same time. + irr::core::array EnvMap; HKL KEYBOARD_INPUT_HKL=0; unsigned int KEYBOARD_INPUT_CODEPAGE = 1252; @@ -691,10 +691,13 @@ namespace irr::CIrrDeviceWin32* getDeviceFromHWnd(HWND hWnd) { - irr::core::list::Iterator it = EnvMap.begin(); - for (; it!= EnvMap.end(); ++it) - if ((*it).hWnd == hWnd) - return (*it).irrDev; + const irr::u32 end = EnvMap.size(); + for ( irr::u32 i=0; i < end; ++i ) + { + const SEnvMapper& env = EnvMap[i]; + if ( env.hWnd == hWnd ) + return env.irrDev; + } return 0; } @@ -1132,13 +1135,11 @@ CIrrDeviceWin32::~CIrrDeviceWin32() delete JoyControl; // unregister environment - - irr::core::list::Iterator it = EnvMap.begin(); - for (; it!= EnvMap.end(); ++it) + for (u32 i=0; i< EnvMap.size(); ++i) { - if ((*it).hWnd == HWnd) + if (EnvMap[i].hWnd == HWnd) { - EnvMap.erase(it); + EnvMap.erase(i); break; } }