[MPlayer-dev-eng] [PATCH] input: optimize key_names list.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat Feb 13 23:45:37 CET 2016


Avoid relocations for string pointers.
---
 input/input.c | 8 ++++----
 input/input.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/input/input.c b/input/input.c
index b560c69..0f25553 100644
--- a/input/input.c
+++ b/input/input.c
@@ -372,7 +372,7 @@ static const mp_key_name_t key_names[] = {
 
   { KEY_CLOSE_WIN, "CLOSE_WIN" },
 
-  { 0, NULL }
+  { 0, "" }
 };
 
 // This is the default binding. The content of input.conf overrides these.
@@ -1463,7 +1463,7 @@ static char*
 mp_input_get_key_name(int key) {
   int i;
 
-  for(i = 0; key_names[i].name != NULL; i++) {
+  for(i = 0; key_names[i].name[0]; i++) {
     if(key_names[i].key == key)
       return key_names[i].name;
   }
@@ -1489,7 +1489,7 @@ mp_input_get_key_from_name(const char *name) {
   } else if(len > 2 && strncasecmp("0x",name,2) == 0)
     return strtol(name,NULL,16);
 
-  for(i = 0; key_names[i].name != NULL; i++) {
+  for(i = 0; key_names[i].name[0]; i++) {
     if(strcasecmp(key_names[i].name,name) == 0)
       return key_names[i].key;
   }
@@ -1857,7 +1857,7 @@ mp_input_register_options(m_config_t* cfg) {
 static int mp_input_print_key_list(m_option_t* cfg) {
   int i;
   printf("\n");
-  for(i= 0; key_names[i].name != NULL ; i++)
+  for(i= 0; key_names[i].name[0] ; i++)
     printf("%s\n",key_names[i].name);
   exit(0);
 }
diff --git a/input/input.h b/input/input.h
index 3e1b463..f13729d 100644
--- a/input/input.h
+++ b/input/input.h
@@ -229,7 +229,7 @@ typedef struct mp_cmd_bind {
 
 typedef struct mp_key_name {
   int key;
-  char* name;
+  char name[20];
 } mp_key_name_t;
 
 // These typedefs are for the drivers. They are the functions used to retrieve
-- 
2.7.0



More information about the MPlayer-dev-eng mailing list