[vlc-commits] modules: sort modules by priority during loading

Rémi Denis-Courmont git at videolan.org
Sun Jun 18 14:31:28 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 18 15:12:13 2017 +0300| [84905c402696ec74b1067121e15aeeee64026cff] | committer: Rémi Denis-Courmont

modules: sort modules by priority during loading

This avoids applying the same sorting algorithm on the same table over
and over.

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

 src/modules/bank.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/modules/bank.c b/src/modules/bank.c
index 6c3f53e332..4cc0e9a74e 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -71,6 +71,26 @@ static void vlc_modcap_free(void *data)
     free(cap);
 }
 
+static int vlc_module_cmp (const void *a, const void *b)
+{
+    const module_t *const *ma = a, *const *mb = b;
+    /* Note that qsort() uses _ascending_ order,
+     * so the smallest module is the one with the biggest score. */
+    return (*mb)->i_score - (*ma)->i_score;
+}
+
+static void vlc_modcap_sort(const void *node, const VISIT which,
+                            const int depth)
+{
+    vlc_modcap_t *const *cp = node, *cap = *cp;
+
+    if (which != postorder && which != leaf)
+        return;
+
+    qsort(cap->modv, cap->modc, sizeof (*cap->modv), vlc_module_cmp);
+    (void) depth;
+}
+
 static struct
 {
     vlc_mutex_t lock;
@@ -648,6 +668,8 @@ size_t module_LoadPlugins (vlc_object_t *obj)
 #endif
         config_UnsortConfig ();
         config_SortConfig ();
+
+        twalk(modules.caps_tree, vlc_modcap_sort);
     }
     vlc_mutex_unlock (&modules.lock);
 
@@ -700,14 +722,6 @@ module_t **module_list_get (size_t *n)
     return tab;
 }
 
-static int modulecmp (const void *a, const void *b)
-{
-    const module_t *const *ma = a, *const *mb = b;
-    /* Note that qsort() uses _ascending_ order,
-     * so the smallest module is the one with the biggest score. */
-    return (*mb)->i_score - (*ma)->i_score;
-}
-
 /**
  * Builds a sorted list of all VLC modules with a given capability.
  * The list is sorted from the highest module score to the lowest.
@@ -732,8 +746,6 @@ ssize_t module_list_cap (module_t ***restrict list, const char *name)
     if (unlikely(tab == NULL))
         return -1;
 
-    /* TODO: Sort the table once. */
     memcpy(tab, cap->modv, sizeof (*tab) * n);
-    qsort (*list, n, sizeof (*tab), modulecmp);
     return n;
 }



More information about the vlc-commits mailing list