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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user