optimized get_keycode

This commit is contained in:
sezanzeb 2020-11-23 18:47:57 +01:00
parent f5e734316d
commit 7b89e8a46f

View File

@ -31,13 +31,18 @@ from keymapper.paths import get_config_path
def update_reverse_mapping(func):
"""Generate a reverse mapping to optimize reverse lookups."""
"""Generate a reverse mapping to optimize reverse lookups.
If _mapping contains `20: "a, A"`,
reverse mapping will contain `"a": 20, "A": 20`
"""
def wrapper(self, *args, **kwargs):
func(self, *args, **kwargs)
self._reverse_mapping = {
value: key for key, value
in self._mapping.items()
}
self._reverse_mapping = {}
for key, value in self._mapping.items():
for character in value.split(','):
self._reverse_mapping[character.strip()] = key
return wrapper