gst/gstregistry.c: Reduce the number of stat() calls for every file from three times...
authorSimon Holm Thøgersen <odie@cs.aau.dk>
Mon, 24 Nov 2008 09:59:07 +0000 (09:59 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Mon, 24 Nov 2008 09:59:07 +0000 (09:59 +0000)
Original commit message from CVS:
Patch by: Simon Holm Thøgersen <odie at cs dot aau dot dk>
* gst/gstregistry.c: (gst_registry_scan_path_level):
Reduce the number of stat() calls for every file from three times
to one time. Fixes bug #560360.

ChangeLog
gst/gstregistry.c

index 2fda3ce..f3bc8ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-11-24  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
+
+       Patch by: Simon Holm Thøgersen <odie at cs dot aau dot dk>
+
+       * gst/gstregistry.c: (gst_registry_scan_path_level):
+       Reduce the number of stat() calls for every file from three times
+       to one time. Fixes bug #560360.
+
 2008-11-22  Wim Taymans  <wim.taymans@collabora.co.uk>
 
        * libs/gst/base/gstbasetransform.c:
 2008-11-22  Wim Taymans  <wim.taymans@collabora.co.uk>
 
        * libs/gst/base/gstbasetransform.c:
index 1c1d27a..d3e8271 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>
 
+/* For g_stat () */
+#include <glib/gstdio.h>
 
 #include "gstinfo.h"
 #include "gstregistry.h"
 
 #include "gstinfo.h"
 #include "gstregistry.h"
@@ -808,9 +810,17 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
     return FALSE;
 
   while ((dirent = g_dir_read_name (dir))) {
     return FALSE;
 
   while ((dirent = g_dir_read_name (dir))) {
+    struct stat file_status;
+
     filename = g_strjoin ("/", path, dirent, NULL);
     filename = g_strjoin ("/", path, dirent, NULL);
+    if (g_stat (filename, &file_status) < 0) {
+      /* Plugin will be removed from cache after the scan completes if it
+       * is still marked 'cached' */
+      g_free (filename);
+      continue;
+    }
 
 
-    if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
+    if (file_status.st_mode & S_IFDIR) {
       /* skip the .debug directory, these contain elf files that are not
        * useful or worse, can crash dlopen () */
       if (g_str_equal (dirent, ".debug")) {
       /* skip the .debug directory, these contain elf files that are not
        * useful or worse, can crash dlopen () */
       if (g_str_equal (dirent, ".debug")) {
@@ -831,7 +841,7 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
       g_free (filename);
       continue;
     }
       g_free (filename);
       continue;
     }
-    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
+    if (!(file_status.st_mode & S_IFREG)) {
       GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
       g_free (filename);
       continue;
       GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
       g_free (filename);
       continue;
@@ -853,15 +863,6 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
      * was already seen by the registry, we ignore it */
     plugin = gst_registry_lookup (registry, filename);
     if (plugin) {
      * was already seen by the registry, we ignore it */
     plugin = gst_registry_lookup (registry, filename);
     if (plugin) {
-      struct stat file_status;
-
-      if (stat (filename, &file_status)) {
-        /* Plugin will be removed from cache after the scan completes if it
-         * is still marked 'cached' */
-        g_free (filename);
-        gst_object_unref (plugin);
-        continue;
-      }
       if (plugin->registered) {
         GST_DEBUG_OBJECT (registry,
             "plugin already registered from path \"%s\"",
       if (plugin->registered) {
         GST_DEBUG_OBJECT (registry,
             "plugin already registered from path \"%s\"",