From 7525befadbcef3f5ffece8a936991306c72a320a Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 31 May 2019 10:09:10 +0200 Subject: [PATCH] path_get_path: Narrow string before This cuts down on the wcs2string here by ~25%. The better solution would be to cache narrow versions of $PATH, since we compute that over and over and over and over again, while it rarely changes. Or we could add a full path-cache (where which command is), but that's much harder to invalidate. See #5905. --- src/path.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/path.cpp b/src/path.cpp index 6aa81b8b8..51b3ae7d7 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -39,12 +39,13 @@ static bool path_get_path_core(const wcstring &cmd, wcstring *out_path, // If the command has a slash, it must be an absolute or relative path and thus we don't bother // looking for a matching command. if (cmd.find(L'/') != wcstring::npos) { - if (waccess(cmd, X_OK) != 0) { + std::string narrow = wcs2string(cmd); + if (access(narrow.c_str(), X_OK) != 0) { return false; } struct stat buff; - if (wstat(cmd, &buff)) { + if (stat(narrow.c_str(), &buff)) { return false; } if (S_ISREG(buff.st_mode)) { @@ -66,9 +67,10 @@ static bool path_get_path_core(const wcstring &cmd, wcstring *out_path, for (auto next_path : *pathsv) { if (next_path.empty()) continue; append_path_component(next_path, cmd); - if (waccess(next_path, X_OK) == 0) { + std::string narrow = wcs2string(next_path); + if (access(narrow.c_str(), X_OK) == 0) { struct stat buff; - if (wstat(next_path, &buff) == -1) { + if (stat(narrow.c_str(), &buff) == -1) { if (errno != EACCES) { wperror(L"stat"); }