Provide an optimized override of get_pwd_slash()

This commit is contained in:
ridiculousfish 2019-06-10 10:26:21 -07:00
parent 38a7c77e4b
commit aa950e5c13
2 changed files with 12 additions and 1 deletions

View File

@ -1306,6 +1306,14 @@ std::shared_ptr<environment_t> env_stack_t::snapshot() const { return acquire_im
void env_stack_t::set_argv(wcstring_list_t argv) { set(L"argv", ENV_LOCAL, std::move(argv)); }
wcstring env_stack_t::get_pwd_slash() const {
wcstring pwd = acquire_impl()->perproc_data().pwd;
if (!string_suffixes_string(L"/", pwd)) {
pwd.push_back(L'/');
}
return pwd;
}
void env_stack_t::push(bool new_scope) {
auto impl = acquire_impl();
if (new_scope) {

View File

@ -199,7 +199,7 @@ class environment_t {
virtual ~environment_t();
/// Returns the PWD with a terminating slash.
wcstring get_pwd_slash() const;
virtual wcstring get_pwd_slash() const;
};
/// The null environment contains nothing.
@ -296,6 +296,9 @@ class env_stack_t final : public environment_t {
/// Sets up argv as the given list of strings.
void set_argv(wcstring_list_t argv);
/// Slightly optimized implementation.
wcstring get_pwd_slash() const override;
// Compatibility hack; access the "environment stack" from back when there was just one.
static const std::shared_ptr<env_stack_t> &principal_ref();
static env_stack_t &principal() { return *principal_ref(); }