Skip to content
This repository
Browse code

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

…ookup - that's what const references are for
  • Loading branch information...
commit 88e9d817ae47e70d99f3bad33040f183305a64b2 1 parent d2c92e3
authored June 18, 2011
18  xbmc/input/ButtonTranslator.cpp
@@ -782,23 +782,23 @@ CAction CButtonTranslator::GetAction(int window, const CKey &key, bool fallback)
782 782
   return action;
783 783
 }
784 784
 
785  
-std::map<CStdString, std::map<int, CButtonTranslator::buttonMap> >::iterator CButtonTranslator::GetActiveButtonMap()
  785
+const std::map<int, CButtonTranslator::buttonMap> &CButtonTranslator::GetDeviceMap() const
786 786
 {
787  
-  std::map<CStdString, std::map<int, buttonMap> >::iterator activeMapIt = deviceMappings.find(g_settings.m_activeKeyboardMapping);
  787
+  std::map<CStdString, std::map<int, buttonMap> >::const_iterator activeMapIt = deviceMappings.find(g_settings.m_activeKeyboardMapping);
788 788
   if (activeMapIt == deviceMappings.end())
789  
-    return deviceMappings.find("default");
790  
-  return activeMapIt;
  789
+    return deviceMappings.find("default")->second;
  790
+  return activeMapIt->second;
791 791
 }
792 792
 
793  
-int CButtonTranslator::GetActionCode(int window, const CKey &key, CStdString &strAction)
  793
+int CButtonTranslator::GetActionCode(int window, const CKey &key, CStdString &strAction) const
794 794
 {
795 795
   uint32_t code = key.GetButtonCode();
796 796
 
797  
-  std::map<int, buttonMap> deviceMap = (*GetActiveButtonMap()).second;
798  
-  map<int, buttonMap>::iterator it = deviceMap.find(window);
  797
+  const std::map<int, buttonMap> &deviceMap = GetDeviceMap();
  798
+  map<int, buttonMap>::const_iterator it = deviceMap.find(window);
799 799
   if (it == deviceMap.end())
800 800
     return 0;
801  
-  buttonMap::iterator it2 = (*it).second.find(code);
  801
+  buttonMap::const_iterator it2 = (*it).second.find(code);
802 802
   int action = 0;
803 803
   while (it2 != (*it).second.end())
804 804
   {
@@ -812,7 +812,7 @@ int CButtonTranslator::GetActionCode(int window, const CKey &key, CStdString &st
812 812
   {
813 813
     CLog::Log(LOGDEBUG, "%s: Trying Hardy keycode for %#04x", __FUNCTION__, code);
814 814
     code &= ~0x0F00;
815  
-    buttonMap::iterator it2 = (*it).second.find(code);
  815
+    buttonMap::const_iterator it2 = (*it).second.find(code);
816 816
     while (it2 != (*it).second.end())
817 817
     {
818 818
       action = (*it2).second.id;
4  xbmc/input/ButtonTranslator.h
@@ -98,8 +98,8 @@ class CButtonTranslator
98 98
   typedef std::multimap<uint32_t, CButtonAction> buttonMap; // our button map to fill in
99 99
   
100 100
   std::map<CStdString, std::map<int, buttonMap> > deviceMappings;
101  
-  std::map<CStdString, std::map<int, buttonMap> >::iterator GetActiveButtonMap();
102  
-  int GetActionCode(int window, const CKey &key, CStdString &strAction);
  101
+  const std::map<int, buttonMap> &GetDeviceMap() const;
  102
+  int GetActionCode(int window, const CKey &key, CStdString &strAction) const;
103 103
 
104 104
   static uint32_t TranslateGamepadString(const char *szButton);
105 105
   static uint32_t TranslateRemoteString(const char *szButton);

0 notes on commit 88e9d81

Please sign in to comment.
Something went wrong with that request. Please try again.