[vlc-commits] modules: simplify storage of choices in cache

Rémi Denis-Courmont git at videolan.org
Tue Aug 14 23:59:41 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Aug 15 00:58:21 2012 +0300| [d70cda889b72595f17df9bb15700f32420883161] | committer: Rémi Denis-Courmont

modules: simplify storage of choices in cache

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d70cda889b72595f17df9bb15700f32420883161
---

 src/modules/cache.c |   84 +++++++++++++++++----------------------------------
 1 file changed, 27 insertions(+), 57 deletions(-)

diff --git a/src/modules/cache.c b/src/modules/cache.c
index 3c5107d..8075e4f 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -59,7 +59,7 @@ static int    CacheLoadConfig  ( module_t *, FILE * );
 
 /* Sub-version number
  * (only used to avoid breakage in dev version when cache structure changes) */
-#define CACHE_SUBVERSION_NUM 18
+#define CACHE_SUBVERSION_NUM 19
 
 /* Cache filename */
 #define CACHE_NAME "plugins.dat"
@@ -321,49 +321,27 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
             p_module->p_config[i].value.psz =
                     (p_module->p_config[i].orig.psz != NULL)
                         ? strdup (p_module->p_config[i].orig.psz) : NULL;
+
+            p_module->p_config[i].ppsz_list =
+                      xmalloc( p_module->p_config[i].i_list * sizeof(char *) );
+            for( int j = 0; j < p_module->p_config[i].i_list; j++ )
+                LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
         }
         else
+        {
             memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
                     sizeof (p_module->p_config[i].value));
-
-        if( p_module->p_config[i].i_list )
-        {
-            if( p_module->p_config[i].ppsz_list )
-            {
-                p_module->p_config[i].ppsz_list =
-                    xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
-                if( p_module->p_config[i].ppsz_list )
-                {
-                    int j;
-                    for( j = 0; j < p_module->p_config[i].i_list; j++ )
-                        LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
-                    p_module->p_config[i].ppsz_list[j] = NULL;
-                }
-            }
-            if( p_module->p_config[i].ppsz_list_text )
-            {
-                p_module->p_config[i].ppsz_list_text =
-                    xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
-                if( p_module->p_config[i].ppsz_list_text )
-                {
-                    int j;
-                    for( j = 0; j < p_module->p_config[i].i_list; j++ )
-                        LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
-                    p_module->p_config[i].ppsz_list_text[j] = NULL;
-                }
-            }
-            if( p_module->p_config[i].pi_list )
-            {
-                p_module->p_config[i].pi_list =
-                    xmalloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
-                if( p_module->p_config[i].pi_list )
-                {
-                    for (int j = 0; j < p_module->p_config[i].i_list; j++)
-                        LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
-                }
-            }
+            p_module->p_config[i].pi_list =
+                         xmalloc( p_module->p_config[i].i_list * sizeof(int) );
+            for( int j = 0; j < p_module->p_config[i].i_list; j++ )
+                LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
         }
 
+        p_module->p_config[i].ppsz_list_text =
+                      xmalloc( p_module->p_config[i].i_list * sizeof(char *) );
+        for( int j = 0; j < p_module->p_config[i].i_list; j++ )
+            LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
+
         if( p_module->p_config[i].i_action )
         {
             p_module->p_config[i].ppf_action =
@@ -468,7 +446,7 @@ static int CacheSaveBank (FILE *file, const module_cache_t *cache,
         goto error;
 
 #define SAVE_IMMEDIATE( a ) \
-    if (fwrite (&a, sizeof(a), 1, file) != 1) \
+    if (fwrite (&(a), sizeof(a), 1, file) != 1) \
         goto error
 #define SAVE_STRING( a ) \
     { \
@@ -560,28 +538,20 @@ static int CacheSaveConfig (FILE *file, const module_t *p_module)
         SAVE_STRING( p_module->p_config[i].psz_longtext );
 
         if (IsConfigStringType (p_module->p_config[i].i_type))
+        {
             SAVE_STRING( p_module->p_config[i].orig.psz );
-
-        if( p_module->p_config[i].i_list )
+            for (int j = 0; j < p_module->p_config[i].i_list; j++)
+                SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
+        }
+        else
         {
-            if( p_module->p_config[i].ppsz_list )
-            {
-                for (int j = 0; j < p_module->p_config[i].i_list; j++)
-                    SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
-            }
-
-            if( p_module->p_config[i].ppsz_list_text )
-            {
-                for (int j = 0; j < p_module->p_config[i].i_list; j++)
-                    SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
-            }
-            if( p_module->p_config[i].pi_list )
-            {
-                for (int j = 0; j < p_module->p_config[i].i_list; j++)
-                    SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
-            }
+            for (int j = 0; j < p_module->p_config[i].i_list; j++)
+                SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
         }
 
+        for (int j = 0; j < p_module->p_config[i].i_list; j++)
+            SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
+
         for (int j = 0; j < p_module->p_config[i].i_action; j++)
             SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
     }



More information about the vlc-commits mailing list