[gst-devel] [PATCH] Reduce the number of stat calls for each plugin from 3 to 1.

Jan Schmidt thaytan at noraisin.net
Sat Nov 8 20:02:56 CET 2008


Hi Simon,

This looks like a good idea. I think it'll need some more work to remain
portable to Windows. I don't think the S_ISDIR and S_ISREG macros exist
there.

J.

On Fri, 2008-11-07 at 21:42 +0100, Simon Holm Thøgersen wrote:
> 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\"",
-- 
Jan Schmidt <thaytan at noraisin.net>





More information about the gstreamer-devel mailing list