optimise: pass all large objects (std::function, std::string, structs) by const ref rather than value.

really, these functions should be passed by && and using std::forward on assignment.
however, this means writing a lot of extra code for every single class, as well as explicitly calling move
in a lot of cases.

In the case of std::string, passing by value and calling std::move is the correct approach, especially if the
string is created as an rvalue, then it is only created once and moved into the dest.
Whereas with a const ref, the string is created and then copied into the dst, basically creating 2 copies.
The same thing happens std::function, and well any object.

However, accepting everything by value sucks if you call a constructor from within a constructor, as now you need to create 2 impls
that accept by value and the other by rvalue. All of this extra code to have a more efficent impl just isn't worth it when, going by
the benchmarks, makes no measurable difference (i count anything within >= 1ms as measurable).
This commit is contained in:
ITotalJustice
2025-08-04 18:58:20 +01:00
parent 9fe9c9d491
commit 54d73a6d3b
36 changed files with 127 additions and 133 deletions

View File

@@ -104,7 +104,7 @@ struct Config {
u32 limit{18};
bool nsfw{false};
void SetQuery(std::string new_query) {
void SetQuery(const std::string& new_query) {
query = new_query;
}
@@ -112,7 +112,7 @@ struct Config {
query.clear();
}
void SetCreator(Creator new_creator) {
void SetCreator(const Creator& new_creator) {
creator = new_creator.id;
}