From c83f7d39585e6b1e61ff0b8208dc70db77207e2d Mon Sep 17 00:00:00 2001 From: staphen Date: Wed, 26 Oct 2022 13:55:19 -0400 Subject: [PATCH] Avoid copy construction of PadmapperOptions::Action --- Source/options.cpp | 2 +- Source/options.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/options.cpp b/Source/options.cpp index 568e21384..594862762 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -1591,7 +1591,7 @@ bool PadmapperOptions::Action::SetValue(ControllerButtonCombo value) void PadmapperOptions::AddAction(string_view key, const char *name, const char *description, ControllerButtonCombo defaultInput, std::function actionPressed, std::function actionReleased, std::function enable, unsigned index) { - actions.push_front(Action { key, name, description, defaultInput, std::move(actionPressed), std::move(actionReleased), std::move(enable), index }); + actions.emplace_front(key, name, description, defaultInput, std::move(actionPressed), std::move(actionReleased), std::move(enable), index); } void PadmapperOptions::ButtonPressed(ControllerButton button) diff --git a/Source/options.h b/Source/options.h index 192a89f61..92e66b511 100644 --- a/Source/options.h +++ b/Source/options.h @@ -633,6 +633,10 @@ struct KeymapperOptions : OptionCategoryBase { */ class Action final : public OptionEntryBase { public: + // OptionEntryBase::key may be referencing Action::dynamicKey. + // The implicit copy constructor would copy that reference instead of referencing the copy. + Action(const Action &) = delete; + [[nodiscard]] string_view GetName() const override; [[nodiscard]] OptionEntryType GetType() const override { @@ -689,6 +693,12 @@ struct PadmapperOptions : OptionCategoryBase { */ class Action final : public OptionEntryBase { public: + Action(string_view key, const char *name, const char *description, ControllerButtonCombo defaultInput, std::function actionPressed, std::function actionReleased, std::function enable, unsigned index); + + // OptionEntryBase::key may be referencing Action::dynamicKey. + // The implicit copy constructor would copy that reference instead of referencing the copy. + Action(const Action &) = delete; + [[nodiscard]] string_view GetName() const override; [[nodiscard]] OptionEntryType GetType() const override { @@ -703,7 +713,6 @@ struct PadmapperOptions : OptionCategoryBase { bool SetValue(ControllerButtonCombo value); private: - Action(string_view key, const char *name, const char *description, ControllerButtonCombo defaultInput, std::function actionPressed, std::function actionReleased, std::function enable, unsigned index); ControllerButtonCombo defaultInput; std::function actionPressed; std::function actionReleased;