]> git.sesse.net Git - vlc/blobdiff - src/modules/cache.c
Modules: use a dynamic array for the shortcuts (this save 40K of memory on a 64bit...
[vlc] / src / modules / cache.c
index c6997111e9da9a7fced3ded82ecc0b3976e1549a..fd15dc991bce9cd49b4261d11cc20162a1233049 100644 (file)
@@ -67,6 +67,7 @@ static int    CacheLoadConfig  ( module_t *, FILE * );
 /* Magic for the cache filename */
 #define CACHENAME_VALUES \
     sizeof(int), sizeof(void *), *(uint8_t *)&(uint16_t){ 0xbe1e }, vlc_CPU()
+#define CACHE_STRING "cache "PACKAGE_NAME" "PACKAGE_VERSION
 
 
 void CacheDelete( vlc_object_t *obj, const char *dir )
@@ -96,7 +97,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
     char *psz_filename;
     FILE *file;
     int j, i_size, i_read;
-    char p_cachestring[sizeof("cache " COPYRIGHT_MESSAGE)];
+    char p_cachestring[sizeof(CACHE_STRING)];
     size_t i_cache;
     module_cache_t **pp_cache = NULL;
     int32_t i_file_size, i_marker;
@@ -143,10 +144,10 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
     fseek( file, sizeof(i_file_size), SEEK_SET );
 
     /* Check the file is a plugins cache */
-    i_size = sizeof("cache " COPYRIGHT_MESSAGE) - 1;
+    i_size = sizeof(CACHE_STRING) - 1;
     i_read = fread( p_cachestring, 1, i_size, file );
     if( i_read != i_size ||
-        memcmp( p_cachestring, "cache " COPYRIGHT_MESSAGE, i_size ) )
+        memcmp( p_cachestring, CACHE_STRING, i_size ) )
     {
         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
         fclose( file );
@@ -252,10 +253,13 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
         LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
         LOAD_STRING( pp_cache[i]->p_module->psz_longname );
         LOAD_STRING( pp_cache[i]->p_module->psz_help );
-        for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
-        {
-            LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
-        }
+
+        LOAD_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
+        pp_cache[i]->p_module->pp_shortcuts =
+                malloc( sizeof( char ** ) * pp_cache[i]->p_module->i_shortcuts );
+        for( j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++ )
+            LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
+
         LOAD_STRING( pp_cache[i]->p_module->psz_capability );
         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
@@ -280,10 +284,12 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
             LOAD_STRING( p_module->psz_shortname );
             LOAD_STRING( p_module->psz_longname );
             LOAD_STRING( p_module->psz_help );
-            for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
-            {
-                LOAD_STRING( p_module->pp_shortcuts[j] ); // FIX
-            }
+
+            LOAD_IMMEDIATE( p_module->i_shortcuts );
+            p_module->pp_shortcuts = malloc( sizeof( char ** ) * p_module->i_shortcuts );
+            for( j = 0; j < p_module->i_shortcuts; j++ )
+                LOAD_STRING( p_module->pp_shortcuts[j] );
+
             LOAD_STRING( p_module->psz_capability );
             LOAD_IMMEDIATE( p_module->i_score );
             LOAD_IMMEDIATE( p_module->b_unloadable );
@@ -498,7 +504,7 @@ static int CacheSaveBank (FILE *file, module_cache_t *const *pp_cache,
         goto error;
 
     /* Contains version number */
-    if (fputs ("cache "COPYRIGHT_MESSAGE, file) == EOF)
+    if (fputs (CACHE_STRING, file) == EOF)
         goto error;
 #ifdef DISTRO_VERSION
     /* Allow binary maintaner to pass a string to detect new binary version*/
@@ -544,10 +550,10 @@ static int CacheSaveBank (FILE *file, module_cache_t *const *pp_cache,
         SAVE_STRING( pp_cache[i]->p_module->psz_shortname );
         SAVE_STRING( pp_cache[i]->p_module->psz_longname );
         SAVE_STRING( pp_cache[i]->p_module->psz_help );
-        for (unsigned j = 0; j < MODULE_SHORTCUT_MAX; j++)
-        {
-            SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
-        }
+        SAVE_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
+        for (unsigned j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++)
+            SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
+
         SAVE_STRING( pp_cache[i]->p_module->psz_capability );
         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_score );
         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
@@ -589,8 +595,9 @@ static int CacheSaveSubmodule( FILE *file, const module_t *p_module )
     SAVE_STRING( p_module->psz_shortname );
     SAVE_STRING( p_module->psz_longname );
     SAVE_STRING( p_module->psz_help );
-    for( unsigned j = 0; j < MODULE_SHORTCUT_MAX; j++ )
-         SAVE_STRING( p_module->pp_shortcuts[j] ); // FIXME
+    SAVE_IMMEDIATE( p_module->i_shortcuts );
+    for( unsigned j = 0; j < p_module->i_shortcuts; j++ )
+         SAVE_STRING( p_module->pp_shortcuts[j] );
 
     SAVE_STRING( p_module->psz_capability );
     SAVE_IMMEDIATE( p_module->i_score );