From bd7fea55c4632811e5a26ad5ac8d7b14efe2a81c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 30 Sep 2018 18:20:59 -0400 Subject: [PATCH] Remove some unnecessary env_var_t usage --- src/expand.cpp | 15 +++++++-------- src/path.cpp | 14 ++++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/expand.cpp b/src/expand.cpp index 44b8a4e50..fba8180cd 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -727,30 +727,29 @@ static void expand_home_directory(wcstring &input) { size_t tail_idx; wcstring username = get_home_directory_name(input, &tail_idx); - maybe_t home; + maybe_t home; if (username.empty()) { // Current users home directory. - home = env_get(L"HOME"); - if (home.missing_or_empty()) { + auto home_var = env_get(L"HOME"); + if (home_var.missing_or_empty()) { input.clear(); return; } + home = home_var->as_string(); tail_idx = 1; } else { - // Some other users home directory. + // Some other user's home directory. std::string name_cstr = wcs2string(username); struct passwd userinfo; struct passwd *result; char buf[8192]; int retval = getpwnam_r(name_cstr.c_str(), &userinfo, buf, sizeof(buf), &result); if (!retval && result) { - home = env_var_t(L"HOME", str2wcstring(userinfo.pw_dir)); + home = str2wcstring(userinfo.pw_dir); } } - maybe_t realhome; - if (home) realhome = wrealpath(home->as_string()); - + maybe_t realhome = (home ? wrealpath(*home) : none()); if (realhome) { input.replace(input.begin(), input.begin() + tail_idx, *realhome); } else { diff --git a/src/path.cpp b/src/path.cpp index e9ba42d44..0e099e05b 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -180,12 +180,14 @@ bool path_get_cdpath(const wcstring &dir, wcstring *out, const wchar_t *wd, paths.push_back(path); } else { // Respect CDPATH. - auto cdpaths = env_vars.get(L"CDPATH"); - if (cdpaths.missing_or_empty()) cdpaths = env_var_t(L"CDPATH", L"."); - - std::vector cdpathsv; - cdpaths->to_list(cdpathsv); - for (auto next_path : cdpathsv) { + wcstring_list_t cdpathsv; + if (auto cdpaths = env_vars.get(L"CDPATH")) { + cdpathsv = cdpaths->as_list(); + } + if (cdpathsv.empty()) { + cdpathsv.push_back(L"."); + } + for (wcstring next_path : cdpathsv) { if (next_path.empty()) next_path = L"."; if (next_path == L"." && wd != NULL) { // next_path is just '.', and we have a working directory, so use the wd instead.