Skip to content

Commit 987dee3

Browse files
committed
libcufetch: the handler function shall return 'std::string' instead of 'const std::string'
'const std::string' by value disables move semantics in some compilers and makes code less efficient
1 parent ba859d7 commit 987dee3

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

include/core-modules.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "cufetch/cufetch.hh"
77

8-
#define MODFUNC(name) const std::string name(__attribute__((unused)) const callbackInfo_t* callbackInfo = nullptr)
8+
#define MODFUNC(name) std::string name(__attribute__((unused)) const callbackInfo_t* callbackInfo = nullptr)
99

1010
// system.cc
1111
inline utsname g_uname_infos;
@@ -89,4 +89,4 @@ MODFUNC(gpu_name);
8989
MODFUNC(gpu_vendor);
9090

9191
#undef MODFUNC
92-
#define MODFUNC(name) const std::string name(__attribute__((unused)) const callbackInfo_t* callbackInfo)
92+
#define MODFUNC(name) std::string name(__attribute__((unused)) const callbackInfo_t* callbackInfo)

include/cufetch/cufetch.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ struct module_t
3535
std::string name;
3636
std::string description;
3737
std::vector<module_t> submodules; /* For best performance, use std::move() when adding modules in here. */
38-
std::function<const std::string(const callbackInfo_t*)> handler;
38+
std::function<std::string(const callbackInfo_t*)> handler;
3939
};
4040

41-
APICALL EXPORT const std::string parse(const std::string& input, const moduleMap_t& modulesInfo, const Config& config);
42-
APICALL EXPORT const std::string get_and_color_percentage(const float n1, const float n2, const callbackInfo_t* callback, const bool invert);
41+
APICALL EXPORT std::string parse(const std::string& input, const moduleMap_t& modulesInfo, const Config& config);
42+
APICALL EXPORT std::string get_and_color_percentage(const float n1, const float n2, const callbackInfo_t* callback, const bool invert);
4343

4444
/* Register a module, and its submodules, to customfetch. */
4545
APICALL EXPORT void cfRegisterModule(const module_t& module);

include/parse.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ std::string parse(const std::string& input, std::string& _, parse_args_t& parse_
9292
* @param parse_args The parse() like arguments
9393
* @param moduleName The module name
9494
*/
95-
const std::string getInfoFromName(const parse_args_t& parse_args, const std::string& moduleName);
95+
std::string getInfoFromName(const parse_args_t& parse_args, const std::string& moduleName);
9696

9797
/*
9898
* Create a colored percentage from parse()

libcufetch/parse.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ std::string get_and_color_percentage(const float n1, const float n2, parse_args_
242242
return parse(fmt::format("{}{:.2f}%${{0}}", color, result), _, parse_args);
243243
}
244244

245-
const std::string getInfoFromName(const parse_args_t& parse_args, const std::string& moduleName)
245+
std::string getInfoFromName(const parse_args_t& parse_args, const std::string& moduleName)
246246
{
247247
std::string name;
248248
name.reserve(moduleName.size());
@@ -841,14 +841,14 @@ EXPORT std::string parse(std::string input, const moduleMap_t& modulesInfo, std:
841841
return ret;
842842
}
843843

844-
APICALL EXPORT const std::string parse(const std::string& input, const moduleMap_t& modulesInfo, const Config& config)
844+
APICALL EXPORT std::string parse(const std::string& input, const moduleMap_t& modulesInfo, const Config& config)
845845
{
846846
std::vector<std::string> nah;
847847
parse_args_t parse_args{ modulesInfo, _, nah, nah, config, true, true, true};
848848
return parse(input, parse_args);
849849
}
850850

851-
APICALL EXPORT const std::string get_and_color_percentage(const float n1, const float n2, const callbackInfo_t* callback, const bool invert)
851+
APICALL EXPORT std::string get_and_color_percentage(const float n1, const float n2, const callbackInfo_t* callback, const bool invert)
852852
{
853853
std::vector<std::string> nah;
854854
parse_args_t parse_args{ callback->modulesInfo, _, nah, nah, callback->config, true, true, true};

src/core-plugins/linux/linux-core-modules.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
#include <string_view>
1111
#include <utility>
1212

13-
#include "config.hpp"
1413
#include "core-modules.hh"
1514
#include "cufetch/cufetch.hh"
1615
#include "fmt/format.h"
1716
#include "util.hpp"
1817

1918
using unused = const callbackInfo_t*;
2019

21-
const std::string amount(const double amount, const moduleArgs_t* moduleArgs)
20+
std::string amount(const double amount, const moduleArgs_t* moduleArgs)
2221
{
2322
constexpr std::array<std::string_view, 32> sorted_valid_prefixes = { "B", "EB", "EiB", "GB", "GiB", "kB",
2423
"KiB", "MB", "MiB", "PB", "PiB", "TB",

0 commit comments

Comments
 (0)