From a9d097cad957582f3c524825493ea4e4bdc16d0c Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Sat, 10 Mar 2018 16:08:21 -0800 Subject: [PATCH] Prefer emplace_back; take argument by value. We copy the QString, so it makes sense to accept it by value and _move_ it into the collection instead. This causes the caller to move any rvalue QString into the function, and then the QString is never actually copied at all. --- include/ComboBoxModel.h | 2 +- src/core/ComboBoxModel.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ComboBoxModel.h b/include/ComboBoxModel.h index ed2465cfb..e4088679f 100644 --- a/include/ComboBoxModel.h +++ b/include/ComboBoxModel.h @@ -49,7 +49,7 @@ public: clear(); } - void addItem( const QString& item, std::unique_ptr loader = nullptr ); + void addItem( QString item, std::unique_ptr loader = nullptr ); void clear(); diff --git a/src/core/ComboBoxModel.cpp b/src/core/ComboBoxModel.cpp index 1c7e2d9c5..c91b4483d 100644 --- a/src/core/ComboBoxModel.cpp +++ b/src/core/ComboBoxModel.cpp @@ -27,9 +27,9 @@ -void ComboBoxModel::addItem( const QString& item, std::unique_ptr loader ) +void ComboBoxModel::addItem( QString item, std::unique_ptr loader ) { - m_items.push_back( std::make_pair( item, std::move(loader) ) ); + m_items.emplace_back( std::move(item), std::move(loader) ); setRange( 0, m_items.size() - 1 ); }