From 7eb4c33cb1418e267e35dce1fef140a710a159a0 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 27 Jul 2015 20:32:33 -0400 Subject: [PATCH] Cache result of getPath() on darwin --- library/Process-darwin.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/Process-darwin.cpp b/library/Process-darwin.cpp index 230809cd3..a485e196d 100644 --- a/library/Process-darwin.cpp +++ b/library/Process-darwin.cpp @@ -259,18 +259,24 @@ uint32_t Process::getTickCount() string Process::getPath() { + static string cached_path = ""; + if (cached_path.size()) + return cached_path; char path[1024]; char *real_path; uint32_t size = sizeof(path); if (getcwd(path, size)) - return string(path); + { + cached_path = string(path); + return cached_path; + } if (_NSGetExecutablePath(path, &size) == 0) { real_path = realpath(path, NULL); } std::string path_string(real_path); int last_slash = path_string.find_last_of("/"); - std::string directory = path_string.substr(0,last_slash); - return directory; + cached_path = path_string.substr(0,last_slash); + return cached_path; } int Process::getPID()