commit 5130c35b8524a3e12c05033731991629bc042517
parent e01651cde18cf75dd0e58b40408c8b6d8ed730f4
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 20 Jan 2020 13:03:28 +0100
tweaks: avoid determining the key code from the key string twice
When assign_keyinfo() gets passed zero as key code, it will call
keycode_from_string() to determine the key code from the string.
So, remember the key code when keycode_from_string() gets called
the first time to avoid the second call.
Diffstat:
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -706,7 +706,7 @@ void parse_binding(char *ptr, bool dobind)
{
char *keyptr = NULL, *keycopy = NULL, *funcptr = NULL, *menuptr = NULL;
keystruct *s, *newsc = NULL;
- int menu, mask = 0;
+ int keycode, menu, mask = 0;
funcstruct *f;
check_for_nonempty_syntax();
@@ -743,7 +743,11 @@ void parse_binding(char *ptr, bool dobind)
else if (keycopy[0] != '^' && keycopy[0] != 'M' && keycopy[0] != 'F') {
jot_error(N_("Key name must begin with \"^\", \"M\", or \"F\""));
goto free_things;
- } else if (keycode_from_string(keycopy) < 0) {
+ }
+
+ keycode = keycode_from_string(keycopy);
+
+ if (keycode < 0) {
jot_error(N_("Key name %s is invalid"), keycopy);
goto free_things;
}
@@ -828,7 +832,7 @@ void parse_binding(char *ptr, bool dobind)
}
newsc->menus = menu;
- assign_keyinfo(newsc, keycopy, 0);
+ assign_keyinfo(newsc, keycopy, keycode);
/* Disallow rebinding ^[ and frequent escape-sequence starter "Esc [". */
if ((!newsc->meta && newsc->keycode == ESC_CODE) ||