From 0af5bbb1101d64b98a4b6a67e17c98654e794161 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 4 Dec 2013 12:48:32 +0000 Subject: -reduce stat calls by caching result of GNUNET_OS_installation_get_path --- src/util/os_installation.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/util/os_installation.c b/src/util/os_installation.c index a94798d8d..30e729dc6 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c @@ -627,21 +627,24 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) char * GNUNET_OS_get_libexec_binary_path (const char *progname) { + static char *cache; char *libexecdir; char *binary; - if (DIR_SEPARATOR == progname[0]) + if ( (DIR_SEPARATOR == progname[0]) || + (GNUNET_YES == GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)) ) return GNUNET_strdup (progname); - if (GNUNET_YES == GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)) - return GNUNET_strdup (progname); - libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); + if (NULL != cache) + libexecdir = cache; + else + libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); if (NULL == libexecdir) return GNUNET_strdup (progname); GNUNET_asprintf (&binary, "%s%s", libexecdir, progname); - GNUNET_free (libexecdir); + cache = libexecdir; return binary; } -- cgit v1.2.3