Permalink
Browse files

don't copy the entire keymapping structure around with every action l…

…ookup - that's what const references are for
  • Loading branch information...
1 parent d2c92e3 commit 88e9d817ae47e70d99f3bad33040f183305a64b2 Jonathan Marshall committed Jun 17, 2011
Showing with 11 additions and 11 deletions.
  1. +9 −9 xbmc/input/ButtonTranslator.cpp
  2. +2 −2 xbmc/input/ButtonTranslator.h
@@ -782,23 +782,23 @@ CAction CButtonTranslator::GetAction(int window, const CKey &key, bool fallback)
return action;
}
-std::map<CStdString, std::map<int, CButtonTranslator::buttonMap> >::iterator CButtonTranslator::GetActiveButtonMap()
+const std::map<int, CButtonTranslator::buttonMap> &CButtonTranslator::GetDeviceMap() const
{
- std::map<CStdString, std::map<int, buttonMap> >::iterator activeMapIt = deviceMappings.find(g_settings.m_activeKeyboardMapping);
+ std::map<CStdString, std::map<int, buttonMap> >::const_iterator activeMapIt = deviceMappings.find(g_settings.m_activeKeyboardMapping);
if (activeMapIt == deviceMappings.end())
- return deviceMappings.find("default");
- return activeMapIt;
+ return deviceMappings.find("default")->second;
+ return activeMapIt->second;
}
-int CButtonTranslator::GetActionCode(int window, const CKey &key, CStdString &strAction)
+int CButtonTranslator::GetActionCode(int window, const CKey &key, CStdString &strAction) const
{
uint32_t code = key.GetButtonCode();
- std::map<int, buttonMap> deviceMap = (*GetActiveButtonMap()).second;
- map<int, buttonMap>::iterator it = deviceMap.find(window);
+ const std::map<int, buttonMap> &deviceMap = GetDeviceMap();
+ map<int, buttonMap>::const_iterator it = deviceMap.find(window);
if (it == deviceMap.end())
return 0;
- buttonMap::iterator it2 = (*it).second.find(code);
+ buttonMap::const_iterator it2 = (*it).second.find(code);
int action = 0;
while (it2 != (*it).second.end())
{
@@ -812,7 +812,7 @@ int CButtonTranslator::GetActionCode(int window, const CKey &key, CStdString &st
{
CLog::Log(LOGDEBUG, "%s: Trying Hardy keycode for %#04x", __FUNCTION__, code);
code &= ~0x0F00;
- buttonMap::iterator it2 = (*it).second.find(code);
+ buttonMap::const_iterator it2 = (*it).second.find(code);
while (it2 != (*it).second.end())
{
action = (*it2).second.id;
@@ -98,8 +98,8 @@ class CButtonTranslator
typedef std::multimap<uint32_t, CButtonAction> buttonMap; // our button map to fill in
std::map<CStdString, std::map<int, buttonMap> > deviceMappings;
- std::map<CStdString, std::map<int, buttonMap> >::iterator GetActiveButtonMap();
- int GetActionCode(int window, const CKey &key, CStdString &strAction);
+ const std::map<int, buttonMap> &GetDeviceMap() const;
+ int GetActionCode(int window, const CKey &key, CStdString &strAction) const;
static uint32_t TranslateGamepadString(const char *szButton);
static uint32_t TranslateRemoteString(const char *szButton);

0 comments on commit 88e9d81

Please sign in to comment.