vlc | branch: master | Thomas Guillem <[email protected]> | Thu May 18 14:03:07 2017 +0200| [b474d7de790e9cfb98d7fa4dd4ae611926c86014] | committer: Thomas Guillem
linux/dirs: cache the result of config_GetLibDir() On release builds, this slow function is called from config_GetDataDir() (if VLC_DATA_PATH is not defined) each time we probe a lua file. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b474d7de790e9cfb98d7fa4dd4ae611926c86014 --- src/linux/dirs.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/linux/dirs.c b/src/linux/dirs.c index 59af705f84..701f1027fc 100644 --- a/src/linux/dirs.c +++ b/src/linux/dirs.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <string.h> +#include <linux/limits.h> #include <vlc_common.h> #include "libvlc.h" @@ -31,6 +32,23 @@ char *config_GetLibDir (void) { + static struct + { + vlc_mutex_t lock; + char path[PATH_MAX]; + } cache = { + VLC_STATIC_MUTEX, "", + }; + + /* Reading and parsing /proc/self/maps is slow, so cache the value since + * it's guaranteed not to change during the life-time of the process. */ + vlc_mutex_lock(&cache.lock); + if (cache.path[0] != '\0') + { + char *ret = strdup(cache.path); + vlc_mutex_unlock(&cache.lock); + return ret; + } char *path = NULL; /* Find the path to libvlc (i.e. ourselves) */ @@ -72,7 +90,12 @@ char *config_GetLibDir (void) free (line); fclose (maps); error: - return (path != NULL) ? path : strdup (PKGLIBDIR); + if (path == NULL) + path = strdup(PKGLIBDIR); + if (likely(path != NULL && sizeof(cache.path) > strlen(path))) + strcpy(cache.path, path); + vlc_mutex_unlock(&cache.lock); + return path; } char *config_GetDataDir (void) _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
