diff options
author | Στέφανος <sofr.stef@cytanet.com.cy> | 2022-10-04 12:56:14 +0300 |
---|---|---|
committer | Στέφανος <sofr.stef@cytanet.com.cy> | 2022-10-04 12:56:14 +0300 |
commit | ab7fe62e65f363e6161534d58e8de7f98350f964 (patch) | |
tree | c1786994ee431e7719c605efa8de0a8029c8547c | |
parent | 36a180033db62743d70f1332fde3ea1102181555 (diff) |
Fix variable initialization to 'auto' for getB()
It does not make sense to return a `const bool&` as we are dealing with
Boolean literals that are `prvalue`s of type bool.
The compiler is smart enough to do the necessary optimizations wherever
is applicable.
-rw-r--r-- | src/btop_config.hpp | 7 | ||||
-rw-r--r-- | src/btop_draw.cpp | 12 | ||||
-rw-r--r-- | src/btop_menu.cpp | 8 | ||||
-rw-r--r-- | src/btop_tools.cpp | 2 | ||||
-rw-r--r-- | src/freebsd/btop_collect.cpp | 20 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 10 | ||||
-rw-r--r-- | src/osx/btop_collect.cpp | 20 |
7 files changed, 36 insertions, 43 deletions
diff --git a/src/btop_config.hpp b/src/btop_config.hpp index f60e48d..bbebc9b 100644 --- a/src/btop_config.hpp +++ b/src/btop_config.hpp @@ -113,10 +113,3 @@ namespace Config { //* Write the config file to disk void write(); } - - - - - - - diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 3ae4210..abb68fe 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -232,8 +232,8 @@ namespace Draw { const string title, const string title2, const int num) { string out; if (line_color.empty()) line_color = Theme::c("div_line"); - const auto tty_mode = Config::getB("tty_mode"); - const auto rounded = Config::getB("rounded_corners"); + auto tty_mode = Config::getB("tty_mode"); + auto rounded = Config::getB("rounded_corners"); const string numbering = (num == 0) ? "" : Theme::c("hi_fg") + (tty_mode ? std::to_string(num) : Symbols::superscript.at(clamp(num, 0, 9))); const auto& right_up = (tty_mode or not rounded ? Symbols::right_up : Symbols::round_right_up); const auto& left_up = (tty_mode or not rounded ? Symbols::left_up : Symbols::round_left_up); @@ -300,7 +300,7 @@ namespace Draw { } auto& out = Global::clock; - const auto& cpu_bottom = Config::getB("cpu_bottom"); + auto cpu_bottom = Config::getB("cpu_bottom"); const auto& x = Cpu::x; const auto y = (cpu_bottom ? Cpu::y + Cpu::height - 1 : Cpu::y); const auto& width = Cpu::width; @@ -503,9 +503,9 @@ namespace Cpu { string draw(const cpu_info& cpu, const bool force_redraw, const bool data_same) { if (Runner::stopping) return ""; if (force_redraw) redraw = true; - const bool show_temps = (Config::getB("check_temp") and got_sensors); + bool show_temps = (Config::getB("check_temp") and got_sensors); auto single_graph = Config::getB("cpu_single_graph"); - const bool hide_cores = show_temps and (cpu_temp_only or not Config::getB("show_coretemp")); + bool hide_cores = show_temps and (cpu_temp_only or not Config::getB("show_coretemp")); const int extra_width = (hide_cores ? max(6, 6 * b_column_size) : 0); auto& graph_up_field = Config::getS("cpu_graph_upper"); auto& graph_lo_field = Config::getS("cpu_graph_lower"); @@ -1590,7 +1590,7 @@ namespace Draw { //* Calculate and draw cpu box outlines if (Cpu::shown) { using namespace Cpu; - const bool show_temp = (Config::getB("check_temp") and got_sensors); + bool show_temp = (Config::getB("check_temp") and got_sensors); width = round((double)Term::width * width_p / 100); height = max(8, (int)ceil((double)Term::height * (trim(boxes) == "cpu" ? 100 : height_p) / 100)); x = 1; diff --git a/src/btop_menu.cpp b/src/btop_menu.cpp index 3ca22da..c5822f2 100644 --- a/src/btop_menu.cpp +++ b/src/btop_menu.cpp @@ -632,8 +632,8 @@ namespace Menu { msgBox::msgBox() {} msgBox::msgBox(int width, int boxtype, vector<string> content, string title) : width(width), boxtype(boxtype) { - const auto& tty_mode = Config::getB("tty_mode"); - const auto& rounded = Config::getB("rounded_corners"); + auto tty_mode = Config::getB("tty_mode"); + auto rounded = Config::getB("rounded_corners"); const auto& right_up = (tty_mode or not rounded ? Symbols::right_up : Symbols::round_right_up); const auto& left_up = (tty_mode or not rounded ? Symbols::left_up : Symbols::round_left_up); const auto& right_down = (tty_mode or not rounded ? Symbols::right_down : Symbols::round_right_down); @@ -722,7 +722,7 @@ namespace Menu { }; int signalChoose(const string& key) { - auto& s_pid = (Config::getB("show_detailed") and Config::getI("selected_pid") == 0 ? Config::getI("detailed_pid") : Config::getI("selected_pid")); + auto s_pid = (Config::getB("show_detailed") and Config::getI("selected_pid") == 0 ? Config::getI("detailed_pid") : Config::getI("selected_pid")); static int x{}; // defaults to 0 static int y{}; // defaults to 0 static int selected_signal = -1; @@ -852,7 +852,7 @@ namespace Menu { } int signalSend(const string& key) { - auto& s_pid = (Config::getB("show_detailed") and Config::getI("selected_pid") == 0 ? Config::getI("detailed_pid") : Config::getI("selected_pid")); + auto s_pid = (Config::getB("show_detailed") and Config::getI("selected_pid") == 0 ? Config::getI("detailed_pid") : Config::getI("selected_pid")); if (s_pid == 0) return Closed; if (redraw) { atomic_wait(Runner::active); diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp index ab93f00..7e64f74 100644 --- a/src/btop_tools.cpp +++ b/src/btop_tools.cpp @@ -349,7 +349,7 @@ namespace Tools { string floating_humanizer(uint64_t value, const bool shorten, size_t start, const bool bit, const bool per_second) { string out; const size_t mult = (bit) ? 8 : 1; - const bool mega = Config::getB("base_10_sizes"); + bool mega = Config::getB("base_10_sizes"); // taking advantage of type deduction for array creation (since C++17) // combined with string literals (operator""s) diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 9e5be73..bc01333 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -614,9 +614,9 @@ namespace Mem { if (Runner::stopping or (no_update and not current_mem.percent.at("used").empty())) return current_mem; - auto &show_swap = Config::getB("show_swap"); - auto &show_disks = Config::getB("show_disks"); - auto &swap_disk = Config::getB("swap_disk"); + auto show_swap = Config::getB("show_swap"); + auto show_disks = Config::getB("show_disks"); + auto swap_disk = Config::getB("swap_disk"); auto &mem = current_mem; static const bool snapped = (getenv("BTOP_SNAPPED") != NULL); @@ -670,7 +670,7 @@ namespace Mem { double uptime = system_uptime(); auto &disks_filter = Config::getS("disks_filter"); bool filter_exclude = false; - // auto &only_physical = Config::getB("only_physical"); + // auto only_physical = Config::getB("only_physical"); auto &disks = mem.disks; vector<string> filter; if (not disks_filter.empty()) { @@ -806,8 +806,8 @@ namespace Net { auto collect(const bool no_update) -> net_info & { auto &net = current_net; auto &config_iface = Config::getS("net_iface"); - auto &net_sync = Config::getB("net_sync"); - auto &net_auto = Config::getB("net_auto"); + auto net_sync = Config::getB("net_sync"); + auto net_auto = Config::getB("net_auto"); auto new_timestamp = time_ms(); if (not no_update and errors < 3) { @@ -1080,11 +1080,11 @@ namespace Proc { //* Collects and sorts process information from /proc auto collect(const bool no_update) -> vector<proc_info> & { const auto &sorting = Config::getS("proc_sorting"); - const auto &reverse = Config::getB("proc_reversed"); + auto reverse = Config::getB("proc_reversed"); const auto &filter = Config::getS("proc_filter"); - const auto &per_core = Config::getB("proc_per_core"); - const auto &tree = Config::getB("proc_tree"); - const auto &show_detailed = Config::getB("show_detailed"); + auto per_core = Config::getB("proc_per_core"); + auto tree = Config::getB("proc_tree"); + auto show_detailed = Config::getB("show_detailed"); const size_t detailed_pid = Config::getI("detailed_pid"); bool should_filter = current_filter != filter; if (should_filter) current_filter = filter; diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 3bed684..b8b53f1 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1614,12 +1614,12 @@ namespace Proc { //* Collects and sorts process information from /proc auto collect(const bool no_update) -> vector<proc_info>& { const auto& sorting = Config::getS("proc_sorting"); - const auto& reverse = Config::getB("proc_reversed"); + auto reverse = Config::getB("proc_reversed"); const auto& filter = Config::getS("proc_filter"); - const auto& per_core = Config::getB("proc_per_core"); - const auto& should_filter_kernel = Config::getB("proc_filter_kernel"); - const auto& tree = Config::getB("proc_tree"); - const auto& show_detailed = Config::getB("show_detailed"); + auto per_core = Config::getB("proc_per_core"); + auto should_filter_kernel = Config::getB("proc_filter_kernel"); + auto tree = Config::getB("proc_tree"); + auto show_detailed = Config::getB("show_detailed"); const size_t detailed_pid = Config::getI("detailed_pid"); bool should_filter = current_filter != filter; if (should_filter) current_filter = filter; diff --git a/src/osx/btop_collect.cpp b/src/osx/btop_collect.cpp index d7877a1..1ae33c4 100644 --- a/src/osx/btop_collect.cpp +++ b/src/osx/btop_collect.cpp @@ -666,9 +666,9 @@ namespace Mem { if (Runner::stopping or (no_update and not current_mem.percent.at("used").empty())) return current_mem; - auto &show_swap = Config::getB("show_swap"); - auto &show_disks = Config::getB("show_disks"); - auto &swap_disk = Config::getB("swap_disk"); + auto show_swap = Config::getB("show_swap"); + auto show_disks = Config::getB("show_disks"); + auto swap_disk = Config::getB("swap_disk"); auto &mem = current_mem; static const bool snapped = (getenv("BTOP_SNAPPED") != NULL); @@ -712,7 +712,7 @@ namespace Mem { double uptime = system_uptime(); auto &disks_filter = Config::getS("disks_filter"); bool filter_exclude = false; - // auto &only_physical = Config::getB("only_physical"); + // auto only_physical = Config::getB("only_physical"); auto &disks = mem.disks; vector<string> filter; if (not disks_filter.empty()) { @@ -845,8 +845,8 @@ namespace Net { auto collect(const bool no_update) -> net_info & { auto &net = current_net; auto &config_iface = Config::getS("net_iface"); - auto &net_sync = Config::getB("net_sync"); - auto &net_auto = Config::getB("net_auto"); + auto net_sync = Config::getB("net_sync"); + auto net_auto = Config::getB("net_auto"); auto new_timestamp = time_ms(); if (not no_update and errors < 3) { @@ -1108,11 +1108,11 @@ namespace Proc { //* Collects and sorts process information from /proc auto collect(const bool no_update) -> vector<proc_info> & { const auto &sorting = Config::getS("proc_sorting"); - const auto &reverse = Config::getB("proc_reversed"); + auto reverse = Config::getB("proc_reversed"); const auto &filter = Config::getS("proc_filter"); - const auto &per_core = Config::getB("proc_per_core"); - const auto &tree = Config::getB("proc_tree"); - const auto &show_detailed = Config::getB("show_detailed"); + auto per_core = Config::getB("proc_per_core"); + auto tree = Config::getB("proc_tree"); + auto show_detailed = Config::getB("show_detailed"); const size_t detailed_pid = Config::getI("detailed_pid"); bool should_filter = current_filter != filter; if (should_filter) current_filter = filter; |