[glom] Added Utils::const_list() and use it.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Added Utils::const_list() and use it.
- Date: Fri, 18 Mar 2016 20:57:55 +0000 (UTC)
commit 6f9315de11ad9e276b093c3e80de7632653254d2
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Mar 18 14:56:46 2016 +0100
Added Utils::const_list() and use it.
To make it clearer where this is necessary at the moment,
to make it easier to fix it later.
glom/libglom/algorithms_utils.h | 13 +++++++++++++
glom/libglom/data_structure/layout/layoutgroup.cc | 4 +---
glom/libglom/sql_utils.cc | 6 ++----
3 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/glom/libglom/algorithms_utils.h b/glom/libglom/algorithms_utils.h
index 0a79dbc..87ac0b5 100644
--- a/glom/libglom/algorithms_utils.h
+++ b/glom/libglom/algorithms_utils.h
@@ -22,6 +22,9 @@
#define GLOM_ALGORITHMS_UTILS_H
#include <algorithm>
+#include <vector>
+#include <memory>
+
namespace Glom
{
@@ -92,6 +95,16 @@ copy(T_container_input input, T_container_output& output)
std::back_inserter(output));
}
+template<typename T_element>
+decltype(auto)
+const_list(const std::vector<std::shared_ptr<T_element>>& input)
+{
+ std::vector<std::shared_ptr<const T_element>> result; //This should use RVO.
+ Utils::copy(input, result);
+ return result;
+}
+
+
} //namespace Utils
} //namespace Glom
diff --git a/glom/libglom/data_structure/layout/layoutgroup.cc
b/glom/libglom/data_structure/layout/layoutgroup.cc
index 117e029..183d1e7 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.cc
+++ b/glom/libglom/data_structure/layout/layoutgroup.cc
@@ -163,9 +163,7 @@ LayoutGroup::type_list_const_items LayoutGroup::get_items() const
{
//Get a const map from the non-const map:
//TODO_Performance: Surely we should not need to copy the structure just to constize it?
- type_list_const_items result;
- Utils::copy(m_list_items, result);
- return result;
+ return Utils::const_list(m_list_items);
}
LayoutGroup::type_list_const_items LayoutGroup::get_items_recursive() const
diff --git a/glom/libglom/sql_utils.cc b/glom/libglom/sql_utils.cc
index 56adb5a..013c26e 100644
--- a/glom/libglom/sql_utils.cc
+++ b/glom/libglom/sql_utils.cc
@@ -54,8 +54,7 @@ auto find_if_uses_relationship_has_relationship(T_Container& container, const st
Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_with_where_clause(const Glib::ustring& table_name,
const type_vecLayoutFields& fieldsToGet, const Gnome::Gda::SqlExpr& where_clause, const std::shared_ptr<const
Relationship>& extra_join, const type_sort_clause& sort_clause, guint limit)
{
//TODO_Performance:
- type_vecConstLayoutFields constFieldsToGet;
- Utils::copy(fieldsToGet, constFieldsToGet);
+ const auto constFieldsToGet = Utils::const_list(fieldsToGet);
return build_sql_select_with_where_clause(table_name, constFieldsToGet, where_clause, extra_join,
sort_clause, limit);
}
@@ -309,8 +308,7 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_with_where_clause(const Gl
Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_with_key(const Glib::ustring& table_name, const
type_vecLayoutFields& fieldsToGet, const std::shared_ptr<const Field>& key_field, const Gnome::Gda::Value&
key_value, const type_sort_clause& sort_clause, guint limit)
{
//TODO_Performance:
- type_vecConstLayoutFields constFieldsToGet;
- Utils::copy(fieldsToGet, constFieldsToGet);
+ const auto constFieldsToGet = Utils::const_list(fieldsToGet);
return build_sql_select_with_key(table_name, constFieldsToGet, key_field, key_value, sort_clause, limit);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]