From b663b0e818fbc13bd6717adae09933c1a8650197 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Fri, 28 Oct 2016 19:15:05 -0700 Subject: [PATCH] lint: redundant if statement --- src/autoload.cpp | 33 ++++++++++++++++----------------- src/path.cpp | 8 +------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/autoload.cpp b/src/autoload.cpp index d97352b02..c84606081 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -157,6 +157,19 @@ autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcs return func; } +static bool use_cached(autoload_function_t *func, bool really_load, bool allow_stale_functions) { + if (!func) { + return false; // can't use a function that doesn't exist + } + if (really_load && !func->is_placeholder && !func->is_loaded) { + return false; // can't use an unloaded function + } + if (!allow_stale_functions && is_stale(func)) { + return false; // can't use a stale function + } + return true; // I guess we can use it +} + /// This internal helper function does all the real work. By using two functions, the internal /// function can return on various places in the code, and the caller can take care of various /// cleanup work. @@ -169,35 +182,21 @@ autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcs bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list) { // Note that we are NOT locked in this function! - bool reloaded = 0; + bool reloaded = false; // Try using a cached function. If we really want the function to be loaded, require that it be // really loaded. If we're not reloading, allow stale functions. { bool allow_stale_functions = !reload; - scoped_lock locker(lock); autoload_function_t *func = this->get_node(cmd); // get the function - // Determine if we can use this cached function. - bool use_cached; - if (!func) { - // Can't use a function that doesn't exist. - use_cached = false; - } else if (really_load && !func->is_placeholder && !func->is_loaded) { - use_cached = false; // can't use an unloaded function - } else if (!allow_stale_functions && is_stale(func)) { - use_cached = false; // can't use a stale function - } else { - use_cached = true; // I guess we can use it - } - // If we can use this function, return whether we were able to access it. - if (use_cached) { - assert(func != NULL); + if (use_cached(func, really_load, allow_stale_functions)) { return func->is_internalized || func->access.accessible; } } + // The source of the script will end up here. wcstring script_source; bool has_script_source = false; diff --git a/src/path.cpp b/src/path.cpp index f9551d3b9..2a71680ca 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -189,13 +189,7 @@ wcstring path_apply_working_directory(const wcstring &path, const wcstring &work // We're going to make sure that if we want to prepend the wd, that the string has no leading // "/". - bool prepend_wd; - if (path.at(0) == L'/' || path.at(0) == HOME_DIRECTORY) { - prepend_wd = false; - } else { - prepend_wd = true; - } - + bool prepend_wd = path.at(0) != L'/' && path.at(0) != HOME_DIRECTORY; if (!prepend_wd) { // No need to prepend the wd, so just return the path we were given. return path;