[vlc-commits] Do not access the module bank directly from the cache

Rémi Denis-Courmont git at videolan.org
Sat Aug 13 21:24:46 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Aug 13 20:02:40 2011 +0300| [79ca9d672b11e6fe98e4e2d307e20bcf92a44e4f] | committer: Rémi Denis-Courmont

Do not access the module bank directly from the cache

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

 src/modules/cache.c   |   22 ++++++++++++----------
 src/modules/modules.c |    3 ++-
 src/modules/modules.h |    3 ++-
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/modules/cache.c b/src/modules/cache.c
index 2e9437d..c43191f 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -634,23 +634,25 @@ void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
 }
 
 /**
- * Looks up a plugin file in a list of cached plugins.
+ * Looks up a plugin file in a table of cached plugins.
  */
-module_t *CacheFind (module_bank_t *p_bank,
+module_t *CacheFind (module_cache_t *const *entries, size_t count,
                      const char *path, const struct stat *st)
 {
-    module_cache_t **cache = p_bank->pp_loaded_cache;
-    size_t n = p_bank->i_loaded_cache;
+    while (count > 0)
+    {
+        module_cache_t *entry = *(entries++);
 
-    for( size_t i = 0; i < n; i++ )
-        if( !strcmp( cache[i]->path, path )
-         && cache[i]->mtime == st->st_mtime
-         && cache[i]->size == st->st_size)
+        if (!strcmp (entry->path, path)
+         && entry->mtime == st->st_mtime
+         && entry->size == st->st_size)
        {
-            module_t *module = cache[i]->p_module;
-            cache[i]->p_module = NULL;
+            module_t *module = entry->p_module;
+            entry->p_module = NULL; /* Return NULL next time */
             return module;
        }
+       count--;
+    }
 
     return NULL;
 }
diff --git a/src/modules/modules.c b/src/modules/modules.c
index 26ca697..7dde884 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -969,7 +969,8 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
                 p_module->psz_object_name, p_module->psz_longname ); */
     /* Check our plugins cache first then load plugin if needed */
     if( mode == CACHE_USE )
-        p_module = CacheFind( p_bank, path, st );
+        p_module = CacheFind (p_bank->pp_loaded_cache, p_bank->i_loaded_cache,
+                              path, st);
     if( p_module == NULL )
         p_module = AllocatePlugin( p_this, path, true );
     if( p_module == NULL )
diff --git a/src/modules/modules.h b/src/modules/modules.h
index e0a9bd7..2b3e0af 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -150,6 +150,7 @@ void   CacheMerge (vlc_object_t *, module_t *, module_t *);
 void   CacheDelete(vlc_object_t *, const char *);
 size_t CacheLoad  (vlc_object_t *, const char *, module_cache_t ***);
 void   CacheSave  (vlc_object_t *, const char *, module_cache_t *const *, size_t);
-module_t * CacheFind (module_bank_t *, const char *, const struct stat *);
+module_t *CacheFind (module_cache_t *const *, size_t,
+                     const char *, const struct stat *);
 
 #endif /* !LIBVLC_MODULES_H */



More information about the vlc-commits mailing list