]> git.sesse.net Git - vlc/blobdiff - src/modules/entry.c
Modules: use a dynamic array for the shortcuts (this save 40K of memory on a 64bit...
[vlc] / src / modules / entry.c
index 0834ff9adf146f6e62be51a76c73af4f0cef1b24..e0b48d293faed0f5915388378fe527537b6f05ac 100644 (file)
@@ -37,6 +37,7 @@ static void vlc_module_destruct (gc_object_t *obj)
 {
     module_t *module = vlc_priv (obj, module_t);
 
+    free (module->pp_shortcuts);
     free (module->psz_object_name);
     free (module);
 }
@@ -59,8 +60,8 @@ module_t *vlc_module_create (vlc_object_t *obj)
     module->psz_shortname = NULL;
     module->psz_longname = (char*)default_name;
     module->psz_help = NULL;
-    for (unsigned i = 0; i < MODULE_SHORTCUT_MAX; i++)
-        module->pp_shortcuts[i] = NULL;
+    module->pp_shortcuts = NULL;
+    module->i_shortcuts = 0;
     module->psz_capability = (char*)"";
     module->i_score = 1;
     module->b_unloadable = true;
@@ -85,6 +86,7 @@ module_t *vlc_module_create (vlc_object_t *obj)
 static void vlc_submodule_destruct (gc_object_t *obj)
 {
     module_t *module = vlc_priv (obj, module_t);
+    free (module->pp_shortcuts);
     free (module->psz_object_name);
     free (module);
 }
@@ -105,9 +107,9 @@ module_t *vlc_submodule_create (module_t *module)
     module->submodule_count++;
 
     /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
+    submodule->pp_shortcuts = malloc( sizeof( char ** ) );
     submodule->pp_shortcuts[0] = module->pp_shortcuts[0]; /* object name */
-    for (unsigned i = 1; i < MODULE_SHORTCUT_MAX; i++)
-        submodule->pp_shortcuts[i] = NULL;
+    submodule->i_shortcuts = 1;
 
     submodule->psz_object_name = strdup( module->psz_object_name );
     submodule->psz_shortname = module->psz_shortname;
@@ -179,12 +181,9 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
 
         case VLC_MODULE_SHORTCUT:
         {
-            unsigned i;
-            for (i = 0; module->pp_shortcuts[i] != NULL; i++);
-                if (i >= (MODULE_SHORTCUT_MAX - 1))
-                    break;
-
-            module->pp_shortcuts[i] = va_arg (ap, char *);
+            const char *psz_new = va_arg (ap, char*);
+            module->pp_shortcuts = realloc (module->pp_shortcuts, sizeof( char ** ) * (module->i_shortcuts + 1));
+            module->pp_shortcuts[module->i_shortcuts++] = psz_new;
             break;
         }
 
@@ -213,7 +212,10 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
             const char *value = va_arg (ap, const char *);
             free( module->psz_object_name );
             module->psz_object_name = strdup( value );
+            module->pp_shortcuts = malloc( sizeof( char ** ) );
             module->pp_shortcuts[0] = (char*)value; /* dooh! */
+            module->i_shortcuts = 1;
+
             if (module->psz_longname == default_name)
                 module->psz_longname = (char*)value; /* dooh! */
             break;