Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
0366eecd by Lyndon Brown at 2021-07-09T15:33:41+00:00
plugins: capture total module count

...in the modules data structure.

we thus know the precise count of modules up front in places where we want
to know this, avoiding having to process the plugins array to build a count
each time.

 - we thus can improve the efficiency of `module_list_get()`, as done.
 - we thus can simply print the count at the end of `module_LoadPlugins()`
   rather than it having to use a `module_list_get()` call to get that info.

- - - - -


1 changed file:

- src/modules/bank.c


Changes:

=====================================
src/modules/bank.c
=====================================
@@ -96,8 +96,9 @@ static struct
     vlc_mutex_t lock;
     block_t *caches;
     void *caps_tree;
+    size_t count;
     unsigned usage;
-} modules = { VLC_STATIC_MUTEX, NULL, NULL, 0 };
+} modules = { VLC_STATIC_MUTEX, NULL, NULL, 0, 0 };
 
 vlc_plugin_t *vlc_plugins = NULL;
 
@@ -150,6 +151,7 @@ static void vlc_plugin_store(vlc_plugin_t *lib)
 
     lib->next = vlc_plugins;
     vlc_plugins = lib;
+    modules.count += lib->modules_count;
 
     for (module_t *m = lib->module; m != NULL; m = m->next)
         vlc_module_store(m);
@@ -763,6 +765,7 @@ void module_EndBank (bool b_plugins)
         vlc_plugins = NULL;
         modules.caches = NULL;
         modules.caps_tree = NULL;
+        modules.count = 0;
     }
     vlc_mutex_unlock (&modules.lock);
 
@@ -805,10 +808,7 @@ void module_LoadPlugins(vlc_object_t *obj)
     }
     vlc_mutex_unlock (&modules.lock);
 
-    size_t count;
-    module_t **list = module_list_get (&count);
-    module_list_free (list);
-    msg_Dbg (obj, "plug-ins loaded: %zu modules", count);
+    msg_Dbg (obj, "plug-ins loaded: %zu modules", modules.count);
 }
 
 void module_list_free (module_t **list)
@@ -818,26 +818,25 @@ void module_list_free (module_t **list)
 
 module_t **module_list_get (size_t *n)
 {
-    module_t **tab = NULL;
-    size_t i = 0;
-
     assert (n != NULL);
+    *n = modules.count;
+
+    if (unlikely(modules.count == 0))
+        return NULL;
+
+    module_t **tab = malloc(modules.count * sizeof(*tab));
+    if (unlikely(tab == NULL))
+        return NULL;
 
+    size_t i = 0;
     for (vlc_plugin_t *lib = vlc_plugins; lib != NULL; lib = lib->next)
     {
-        module_t **nt = realloc(tab, (i + lib->modules_count) * sizeof (*tab));
-        if (unlikely(nt == NULL))
-        {
-            free (tab);
-            *n = 0;
-            return NULL;
-        }
-
-        tab = nt;
         for (module_t *m = lib->module; m != NULL; m = m->next)
+        {
+            assert(i < modules.count);
             tab[i++] = m;
+        }
     }
-    *n = i;
     return tab;
 }
 



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/0366eecd5382a206748b02273a317187fed7cbe8

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/0366eecd5382a206748b02273a317187fed7cbe8
You're receiving this email because of your account on code.videolan.org.


_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to