[gst-devel] [PATCH] Reduce the number of stat calls for each plugin from 3 to 1.
Simon Holm Thøgersen
odie at cs.aau.dk
Fri Nov 7 21:42:32 CET 2008
The code already called stat directly in one place. By moving this code
further up we avoid doing a stat with g_file_test twice by replacing the
g_file_test calls with similar code that uses the cached stat.
Signed-off-by: Simon Holm Thøgersen <odie at cs.aau.dk>
---
gst/gstregistry.c | 21 ++++++++++-----------
1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/gst/gstregistry.c b/gst/gstregistry.c
index 1c1d27a..6850b91 100644
--- a/gst/gstregistry.c
+++ b/gst/gstregistry.c
@@ -808,9 +808,17 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
return FALSE;
while ((dirent = g_dir_read_name (dir))) {
+ struct stat file_status;
+
filename = g_strjoin ("/", path, dirent, NULL);
+ if (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 (S_ISDIR(file_status.st_mode)) {
/* 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 +839,7 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
g_free (filename);
continue;
}
- if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
+ if (!S_ISREG(file_status.st_mode)) {
GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
g_free (filename);
continue;
@@ -853,15 +861,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) {
- 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\"",
--
1.6.0.2.526.g5c283
More information about the gstreamer-devel
mailing list