[PATCH] input.c: optimize mp_cmd list.

Reimar Döffinger <[email protected]>
Newsgroups gmane.comp.video.mplayer.devel
Message-ID <[email protected]>
Reduce its size and encode strings directly
to avoid relocations.
---
 gui/interface.c  | 2 +-
 gui/ui/actions.c | 2 +-
 input/input.c    | 8 ++------
 input/input.h    | 4 ++--
 4 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/gui/interface.c b/gui/interface.c
index 30a564f..3d98998 100644
--- a/gui/interface.c
+++ b/gui/interface.c
@@ -1262,7 +1262,7 @@ void mplayer(int what, float value, void *data)
 
         mp_cmd       = calloc(1, sizeof(*mp_cmd));
         mp_cmd->id   = MP_CMD_PANSCAN;
-        mp_cmd->name = strdup("panscan");
+        strcpy(mp_cmd->name, "panscan");
         mp_cmd->args[0].v.f = value;
         mp_cmd->args[1].v.i = 1;
         mp_input_queue_cmd(mp_cmd);
diff --git a/gui/ui/actions.c b/gui/ui/actions.c
index 4304817..2728986 100644
--- a/gui/ui/actions.c
+++ b/gui/ui/actions.c
@@ -578,7 +578,7 @@ void uiPause(void)
 
         if (cmd) {
             cmd->id   = MP_CMD_PAUSE;
-            cmd->name = strdup("pause");
+            strcpy(cmd->name, "pause");
             mp_input_queue_cmd(cmd);
         }
     } else
diff --git a/input/input.c b/input/input.c
index 4f80e68..1a52efe 100644
--- a/input/input.c
+++ b/input/input.c
@@ -212,7 +212,7 @@ static const mp_cmd_t mp_cmds[] = {
 
   { MP_CMD_GUI, "gui", 1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
 
-  { 0, NULL, 0, {} }
+  { 0, "", 0, {} }
 };
 
 /// The names of the keys as used in input.conf
@@ -831,7 +831,7 @@ mp_input_parse_cmd(char* str) {
 
   cmd = calloc(1, sizeof(mp_cmd_t));
   cmd->id = cmd_def->id;
-  cmd->name = strdup(cmd_def->name);
+  memcpy(cmd->name, cmd_def->name, sizeof(cmd->name));
   if (pausing == -1) {
     switch (cmd->id) {
       case MP_CMD_KEYDOWN_EVENTS:
@@ -1432,8 +1432,6 @@ mp_cmd_free(mp_cmd_t* cmd) {
 //#endif
   if ( !cmd ) return;
 
-  free(cmd->name);
-
   for(i=0; i < MP_CMD_MAX_ARGS && cmd->args[i].type != -1; i++) {
     if(cmd->args[i].type == MP_CMD_ARG_STRING)
       free(cmd->args[i].v.s);
@@ -1451,8 +1449,6 @@ mp_cmd_clone(mp_cmd_t* cmd) {
 
   ret = malloc(sizeof(mp_cmd_t));
   memcpy(ret,cmd,sizeof(mp_cmd_t));
-  if(cmd->name)
-    ret->name = strdup(cmd->name);
   for(i = 0;  i < MP_CMD_MAX_ARGS && cmd->args[i].type != -1; i++) {
     if(cmd->args[i].type == MP_CMD_ARG_STRING && cmd->args[i].v.s != NULL)
       ret->args[i].v.s = strdup(cmd->args[i].v.s);
diff --git a/input/input.h b/input/input.h
index e723618..3e1b463 100644
--- a/input/input.h
+++ b/input/input.h
@@ -174,7 +174,7 @@ typedef enum {
 #define MP_CMD_ARG_VOID 3
 
 #ifndef MP_CMD_MAX_ARGS
-#define MP_CMD_MAX_ARGS 10
+#define MP_CMD_MAX_ARGS 6
 #endif
 
 // Error codes for the drivers
@@ -215,7 +215,7 @@ typedef struct mp_cmd_arg {
 
 typedef struct mp_cmd {
   int id;
-  char* name;
+  char name[24];
   int nargs;
   mp_cmd_arg_t args[MP_CMD_MAX_ARGS];
   int pausing;
-- 
2.7.0

_______________________________________________
MPlayer-dev-eng mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.