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

@@ -502,7 +502,7 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
nvgRestore(vg);
}
m_list->Draw(vg, theme, std::size(g_option_list), [this](auto* vg, auto* theme, auto v, auto i) {
m_list->Draw(vg, theme, std::size(g_option_list), [this](auto* vg, auto* theme, auto& v, auto i) {
const auto& [x, y, w, h] = v;
const auto text_y = y + (h / 2.f);
auto colour = ThemeEntryID_TEXT;