Web lists-archives.com

Re: [MPlayer-dev-eng] [PATCH] input.c: optimize mp_cmd list.




Reimar Döffinger wrote on Sat, 13 Feb 2016 23:12:32 +0100:

> Reduce its size and encode strings directly
> to avoid relocations.
>  gui/interface.c  | 2 +-
>  gui/ui/actions.c | 2 +-

Untested though. Everything has been calloc'ed. (Win32 GUI was missing.)

Ingo
Index: gui/interface.c
===================================================================
--- gui/interface.c	(revision 37722)
+++ gui/interface.c	(working copy)
@@ -1262,7 +1262,7 @@
 
         mp_cmd       = calloc(1, sizeof(*mp_cmd));
         mp_cmd->id   = MP_CMD_PANSCAN;
-        mp_cmd->name = strdup("panscan");
+        strncpy(mp_cmd->name, "panscan", FF_ARRAY_ELEMS(mp_cmd->name) - 1);
         mp_cmd->args[0].v.f = value;
         mp_cmd->args[1].v.i = 1;
         mp_input_queue_cmd(mp_cmd);
Index: gui/ui/actions.c
===================================================================
--- gui/ui/actions.c	(revision 37705)
+++ gui/ui/actions.c	(working copy)
@@ -50,6 +50,7 @@
 #include "mpcommon.h"
 #include "mplayer.h"
 #include "input/input.h"
+#include "libavutil/common.h"
 #include "libmpdemux/demuxer.h"
 #include "libvo/video_out.h"
 #include "osdep/keycodes.h"
@@ -578,7 +579,7 @@
 
         if (cmd) {
             cmd->id   = MP_CMD_PAUSE;
-            cmd->name = strdup("pause");
+            strncpy(cmd->name, "pause", FF_ARRAY_ELEMS(cmd->name) - 1);
             mp_input_queue_cmd(cmd);
         }
     } else
Index: gui/win32/interface.c
===================================================================
--- gui/win32/interface.c	(revision 37705)
+++ gui/win32/interface.c	(working copy)
@@ -55,6 +55,7 @@
 #include "help_mp.h"
 #include "codec-cfg.h"
 #include "stream/stream.h"
+#include "libavutil/common.h"
 #include "libmpdemux/demuxer.h"
 #include "libmpdemux/stheader.h"
 #ifdef CONFIG_DVDREAD
@@ -348,7 +349,7 @@
         {
             mp_cmd_t * cmd = calloc(1, sizeof(*cmd));
             cmd->id=MP_CMD_MUTE;
-            cmd->name=strdup("mute");
+            strncpy(cmd->name, "mute", FF_ARRAY_ELEMS(cmd->name) - 1);
             mp_input_queue_cmd(cmd);
             break;
         }
@@ -405,7 +406,7 @@
    {
        mp_cmd_t * cmd = calloc(1, sizeof(*cmd));
        cmd->id=MP_CMD_PAUSE;
-       cmd->name=strdup("pause");
+       strncpy(cmd->name, "pause", FF_ARRAY_ELEMS(cmd->name) - 1);
        mp_input_queue_cmd(cmd);
    } else guiInfo.Playing = GUI_PLAY;
 }
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng