mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 22:03:12 +00:00
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.
This commit is contained in:
parent
5ca14904d0
commit
7525befadb
1 changed files with 6 additions and 4 deletions
10
src/path.cpp
10
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
|
// 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.
|
// looking for a matching command.
|
||||||
if (cmd.find(L'/') != wcstring::npos) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat buff;
|
struct stat buff;
|
||||||
if (wstat(cmd, &buff)) {
|
if (stat(narrow.c_str(), &buff)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (S_ISREG(buff.st_mode)) {
|
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) {
|
for (auto next_path : *pathsv) {
|
||||||
if (next_path.empty()) continue;
|
if (next_path.empty()) continue;
|
||||||
append_path_component(next_path, cmd);
|
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;
|
struct stat buff;
|
||||||
if (wstat(next_path, &buff) == -1) {
|
if (stat(narrow.c_str(), &buff) == -1) {
|
||||||
if (errno != EACCES) {
|
if (errno != EACCES) {
|
||||||
wperror(L"stat");
|
wperror(L"stat");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue