mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-08 15:55:32 +08:00
Stop some wcs2stringing
These are paths that barely change, narrowing them *twice* per file load makes absolutely no sense.
This commit is contained in:
parent
6606dfbeb5
commit
7850a10c45
|
@ -391,6 +391,10 @@ void env_universal_t::load_from_fd(int fd, callback_data_list_t &callbacks) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool env_universal_t::load_from_path(const wcstring &path, callback_data_list_t &callbacks) {
|
bool env_universal_t::load_from_path(const wcstring &path, callback_data_list_t &callbacks) {
|
||||||
|
return load_from_path(wcs2string(path), callbacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool env_universal_t::load_from_path(const std::string &path, callback_data_list_t &callbacks) {
|
||||||
|
|
||||||
// Check to see if the file is unchanged. We do this again in load_from_fd, but this avoids
|
// Check to see if the file is unchanged. We do this again in load_from_fd, but this avoids
|
||||||
// opening the file unnecessarily.
|
// opening the file unnecessarily.
|
||||||
|
@ -400,7 +404,7 @@ bool env_universal_t::load_from_path(const wcstring &path, callback_data_list_t
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
autoclose_fd_t fd{wopen_cloexec(path, O_RDONLY)};
|
autoclose_fd_t fd{open_cloexec(path, O_RDONLY)};
|
||||||
if (fd.valid()) {
|
if (fd.valid()) {
|
||||||
FLOGF(uvar_file, L"universal log reading from file");
|
FLOGF(uvar_file, L"universal log reading from file");
|
||||||
this->load_from_fd(fd.fd(), callbacks);
|
this->load_from_fd(fd.fd(), callbacks);
|
||||||
|
@ -469,8 +473,9 @@ void env_universal_t::initialize_at_path(callback_data_list_t &callbacks, wcstri
|
||||||
if (path.empty()) return;
|
if (path.empty()) return;
|
||||||
assert(!initialized() && "Already initialized");
|
assert(!initialized() && "Already initialized");
|
||||||
vars_path_ = std::move(path);
|
vars_path_ = std::move(path);
|
||||||
|
narrow_vars_path_ = wcs2string(vars_path_);
|
||||||
|
|
||||||
if (load_from_path(vars_path_, callbacks)) {
|
if (load_from_path(narrow_vars_path_, callbacks)) {
|
||||||
// Successfully loaded from our normal path.
|
// Successfully loaded from our normal path.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -639,7 +644,7 @@ bool env_universal_t::sync(callback_data_list_t &callbacks) {
|
||||||
// with fire anyways.
|
// with fire anyways.
|
||||||
// If we have no changes, just load.
|
// If we have no changes, just load.
|
||||||
if (modified.empty()) {
|
if (modified.empty()) {
|
||||||
this->load_from_path(vars_path_, callbacks);
|
this->load_from_path(narrow_vars_path_, callbacks);
|
||||||
FLOGF(uvar_file, L"universal log no modifications");
|
FLOGF(uvar_file, L"universal log no modifications");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ class env_universal_t {
|
||||||
private:
|
private:
|
||||||
// Path that we save to. This is set in initialize(). If empty, initialize has not been called.
|
// Path that we save to. This is set in initialize(). If empty, initialize has not been called.
|
||||||
wcstring vars_path_;
|
wcstring vars_path_;
|
||||||
|
std::string narrow_vars_path_;
|
||||||
|
|
||||||
// The table of variables.
|
// The table of variables.
|
||||||
var_table_t vars;
|
var_table_t vars;
|
||||||
|
@ -120,6 +121,8 @@ class env_universal_t {
|
||||||
bool initialized() const { return !vars_path_.empty(); }
|
bool initialized() const { return !vars_path_.empty(); }
|
||||||
|
|
||||||
bool load_from_path(const wcstring &path, callback_data_list_t &callbacks);
|
bool load_from_path(const wcstring &path, callback_data_list_t &callbacks);
|
||||||
|
bool load_from_path(const std::string &path, callback_data_list_t &callbacks);
|
||||||
|
|
||||||
void load_from_fd(int fd, callback_data_list_t &callbacks);
|
void load_from_fd(int fd, callback_data_list_t &callbacks);
|
||||||
|
|
||||||
// Functions concerned with saving.
|
// Functions concerned with saving.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user