Don't pass trivial types as references

Copying trivial types is (mostly) cheaper by value
This commit is contained in:
nobounce 2023-09-13 15:44:32 +02:00
parent be65d50b24
commit 1cd88ee1a9
No known key found for this signature in database
GPG Key ID: CC8B8C464BDC2F39
7 changed files with 16 additions and 16 deletions

View File

@ -110,7 +110,7 @@ namespace Global {
}
//* A simple argument parser
void argumentParser(const int& argc, char **argv) {
void argumentParser(const int argc, char** argv) {
for(int i = 1; i < argc; i++) {
const string argument = argv[i];
if (is_in(argument, "-h", "--help")) {

View File

@ -69,7 +69,7 @@ namespace Config {
inline bool getB(const std::string_view name) { return bools.at(name); }
//* Return integer for config key <name>
inline const int& getI(const std::string_view name) { return ints.at(name); }
inline int getI(const std::string_view name) { return ints.at(name); }
//* Return string for config key <name>
inline const string& getS(const std::string_view name) { return strings.at(name); }
@ -88,7 +88,7 @@ namespace Config {
}
//* Set config key <name> to int <value>
inline void set(const std::string_view name, const int& value) {
inline void set(const std::string_view name, const int value) {
if (_locked(name)) intsTmp.insert_or_assign(name, value);
else ints.at(name) = value;
}

View File

@ -260,12 +260,12 @@ namespace Draw {
out = Fx::reset + line_color;
//? Draw horizontal lines
for (const int& hpos : {y, y + height - 1}) {
for (const int hpos : {y, y + height - 1}) {
out += Mv::to(hpos, x) + Symbols::h_line * (width - 1);
}
//? Draw vertical lines and fill if enabled
for (const int& hpos : iota(y + 1, y + height - 1)) {
for (const int hpos : iota(y + 1, y + height - 1)) {
out += Mv::to(hpos, x) + Symbols::v_line
+ ((fill) ? string(width - 2, ' ') : Mv::r(width - 2))
+ Symbols::v_line;
@ -365,7 +365,7 @@ namespace Draw {
value = clamp(value, 0, 100);
if (not cache.at(value).empty()) return cache.at(value);
auto& out = cache.at(value);
for (const int& i : iota(1, width + 1)) {
for (const int i : iota(1, width + 1)) {
int y = round(i * 100.0 / width);
if (value >= y)
out += Theme::g(color_gradient).at(invert ? 100 - y : y) + Symbols::meter;
@ -391,7 +391,7 @@ namespace Draw {
}
//? Horizontal iteration over values in <data>
for (const int& i : iota(data_offset, static_cast<int>(data.size()))) {
for (const int i : iota(data_offset, static_cast<int>(data.size()))) {
// if (tty_mode and mult and i % 2 != 0) continue;
if (not tty_mode and mult) current = not current;
if (i < 0) {
@ -404,7 +404,7 @@ namespace Draw {
}
//? Vertical iteration over height of graph
for (const int& horizon : iota(0, height)) {
for (const int horizon : iota(0, height)) {
const int cur_high = (height > 1) ? round(100.0 * (height - horizon) / height) : 100;
const int cur_low = (height > 1) ? round(100.0 * (height - (horizon + 1)) / height) : 0;
//? Calculate previous + current value to fit two values in 1 braille character
@ -438,7 +438,7 @@ namespace Draw {
out += graphs.at(current).at(0);
}
else {
for (const int& i : iota(1, height + 1)) {
for (const int i : iota(1, height + 1)) {
if (i > 1) out += Mv::d(1) + Mv::l(width);
if (not color_gradient.empty())
out += (invert) ? Theme::g(color_gradient).at(i * 100 / height) : Theme::g(color_gradient).at(100 - ((i - 1) * 100 / height));
@ -470,7 +470,7 @@ namespace Draw {
}
//? Populate the two switching graph vectors and fill empty space if data size < width
for (const int& i : iota(0, height * 2)) {
for (const int i : iota(0, height * 2)) {
if (tty_mode and i % 2 != current) continue;
graphs[(i % 2 != 0)].push_back((value_width < width) ? ((height == 1) ? Mv::r(1) : " "s) * (width - value_width) : "");
}
@ -483,7 +483,7 @@ namespace Draw {
//? Make room for new characters on graph
if (not tty_mode) current = not current;
for (const int& i : iota(0, height)) {
for (const int i : iota(0, height)) {
if (height == 1 and graphs.at(current).at(i).at(1) == '[') {
if (graphs.at(current).at(i).at(3) == 'C') graphs.at(current).at(i).erase(0, 4);
else graphs.at(current).at(i).erase(0, graphs.at(current).at(i).find_first_of('m') + 4);
@ -1246,7 +1246,7 @@ namespace Proc {
+ title_left + Fx::b + Theme::c("title") + uresize(detailed.entry.name, dgraph_width - pid_str.size() - 7, true) + Fx::ub + title_right;
out += Mv::to(d_y, d_x - 1) + Theme::c("proc_box") + Symbols::div_up + Mv::to(y, d_x - 1) + Symbols::div_down + Theme::c("div_line");
for (const int& i : iota(1, 8)) out += Mv::to(d_y + i, d_x - 1) + Symbols::v_line;
for (const int i : iota(1, 8)) out += Mv::to(d_y + i, d_x - 1) + Symbols::v_line;
const string& t_color = (not alive or selected > 0 ? Theme::c("inactive_fg") : Theme::c("title"));
const string& hi_color = (not alive or selected > 0 ? t_color : Theme::c("hi_fg"));

View File

@ -414,7 +414,7 @@ namespace Input {
}
else if (is_in(key, "+", "-", "space") and Config::getB("proc_tree") and Config::getI("proc_selected") > 0) {
atomic_wait(Runner::active);
auto& pid = Config::getI("selected_pid");
const auto pid = Config::getI("selected_pid");
if (key == "+" or key == "space") Proc::expand = pid;
if (key == "-" or key == "space") Proc::collapse = pid;
no_update = false;

View File

@ -138,7 +138,7 @@ namespace Theme {
namespace {
//* Convert 24-bit colors to 256 colors
int truecolor_to_256(const int& r, const int& g, const int& b) {
int truecolor_to_256(const int r, const int g, const int b) {
//? Use upper 232-255 greyscale values if the downscaled red, green and blue are the same value
if (r == g && g == b) {
return 232 + round(r / 11.0);

View File

@ -511,7 +511,7 @@ namespace Tools {
return (out.empty() ? fallback : out);
}
auto celsius_to(const long long& celsius, const string& scale) -> tuple<long long, string> {
auto celsius_to(const long long celsius, const string& scale) -> tuple<long long, string> {
if (scale == "celsius")
return {celsius, "°C"};
else if (scale == "fahrenheit")

View File

@ -333,7 +333,7 @@ namespace Tools {
string readfile(const std::filesystem::path& path, const string& fallback = "");
//* Convert a celsius value to celsius, fahrenheit, kelvin or rankin and return tuple with new value and unit.
auto celsius_to(const long long& celsius, const string& scale) -> tuple<long long, string>;
auto celsius_to(const long long celsius, const string& scale) -> tuple<long long, string>;
}