From 7002e7de52b6735fb0bd5d99054340d03872423c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Tue, 10 Apr 2018 21:27:56 +0200 Subject: [PATCH] Fix SwitchKeymapByAbbreviation() and use it in place of a for block of equivalent functionality within UsbCommand_ApplyConfig() --- right/src/keymap.c | 4 ++-- right/src/usb_commands/usb_command_apply_config.c | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/right/src/keymap.c b/right/src/keymap.c index 86e9a71..065afcc 100644 --- a/right/src/keymap.c +++ b/right/src/keymap.c @@ -28,9 +28,9 @@ void SwitchKeymapById(uint8_t index) bool SwitchKeymapByAbbreviation(uint8_t length, char *abbrev) { - for (uint8_t i=0; iabbreviationLen == length && strcmp(keymap->abbreviation, abbrev) == 0) { + if (keymap->abbreviationLen == length && memcmp(keymap->abbreviation, abbrev, length) == 0) { SwitchKeymapById(i); return true; } diff --git a/right/src/usb_commands/usb_command_apply_config.c b/right/src/usb_commands/usb_command_apply_config.c index 096e92c..bc337b7 100644 --- a/right/src/usb_commands/usb_command_apply_config.c +++ b/right/src/usb_commands/usb_command_apply_config.c @@ -45,14 +45,8 @@ void UsbCommand_ApplyConfig(void) } // Switch to the keymap of the updated configuration of the same name or the default keymap. - - for (uint8_t keymapId = 0; keymapId < AllKeymapsCount; keymapId++) { - if (AllKeymaps[keymapId].abbreviationLen == oldKeymapAbbreviationLen && - !memcmp(oldKeymapAbbreviation, AllKeymaps[keymapId].abbreviation, oldKeymapAbbreviationLen)) - { - SwitchKeymapById(keymapId); - return; - } + if (SwitchKeymapByAbbreviation(oldKeymapAbbreviationLen, oldKeymapAbbreviation)) { + return; } SwitchKeymapById(DefaultKeymapIndex);