From 799d256e952913524c5e51a59c836e7a4cb52ea5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 19 Dec 2022 20:14:52 +0200 Subject: [PATCH] Cache result of parsing $PATH --- source/virtualfilesystem.cpp | 22 +++++++++++++--------- source/virtualfilesystem.h | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index 783583f..c9bfd23 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -146,17 +146,21 @@ FileTarget *VirtualFileSystem::find_binary(const string &name) path.push_back("/"); else { - string env_path = Msp::getenv("PATH"); - if(!env_path.empty()) + if(sys_bin_path.empty()) { - for(const string &p: split(env_path, ':')) - path.push_back(p); - } - else - { - path.push_back("/bin"); - path.push_back("/usr/bin"); + string env_path = Msp::getenv("PATH"); + if(!env_path.empty()) + { + for(const string &p: split(env_path, ':')) + sys_bin_path.push_back(p); + } + else + { + sys_bin_path.push_back("/bin"); + sys_bin_path.push_back("/usr/bin"); + } } + path = sys_bin_path; } for(const FS::Path &p: path) diff --git a/source/virtualfilesystem.h b/source/virtualfilesystem.h index d74872c..9a25930 100644 --- a/source/virtualfilesystem.h +++ b/source/virtualfilesystem.h @@ -26,6 +26,7 @@ private: Builder &builder; std::map targets; std::set nonexistent; + SearchPath sys_bin_path; public: VirtualFileSystem(Builder &); -- 2.45.2