Adjust move-semantic to query-builder
authorsangwan.kwon <sangwan.kwon@samsung.com>
Wed, 31 Oct 2018 05:57:56 +0000 (14:57 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Mon, 11 Feb 2019 04:25:37 +0000 (13:25 +0900)
- Do not pass large-size structure by value
- Rename table::find to table::compare

Change-Id: I65af36f71a3d90267b906c5cc833e0662ec08c0f
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
include/klay/db/query-builder/database-impl.hxx
include/klay/db/query-builder/database.hxx
include/klay/db/query-builder/table-impl.hxx
include/klay/db/query-builder/table.hxx

index 1312a5f5f785afc46c69bdf4e1cf9ec9d556f8a1..a141fdea808e565db095a71ba3c3b9913f2cca4a 100644 (file)
@@ -29,10 +29,10 @@ template<typename... Base>
 class DatabaseImpl {
 public:
        template<typename Table>
-       std::string getTableName(Table) const noexcept { return std::string(); }
+       std::string getTableName(Table&&) const noexcept { return std::string(); }
 
        template<typename Column>
-       std::string getColumnName(Column column) const noexcept { return std::string(); }
+       std::string getColumnName(Column&&) const noexcept { return std::string(); }
 };
 
 template<typename Front, typename... Rest>
@@ -40,29 +40,31 @@ class DatabaseImpl<Front, Rest...> : public DatabaseImpl<Rest...> {
 public:
        using Table = Front;
 
-       DatabaseImpl(Front front, Rest ...rest) : Base(rest...), table(front) {}
+       DatabaseImpl(Front&& front, Rest&& ...rest) :
+               Base(std::forward<Rest>(rest)...), table(front) {}
 
        Table table;
 
        template<typename Table>
-       std::string getTableName(Table table) const noexcept
+       std::string getTableName(Table&& table) const noexcept
        {
-               if (this->table.find(table))
+               if (this->table.compare(table))
                        return this->table.name;
 
-               return Base::template getTableName<Table>(table);
+               return Base::template getTableName<Table>(std::forward<Table>(table));
        }
 
        template<typename Column>
-       std::string getColumnName(Column column) const noexcept
+       std::string getColumnName(Column&& column) const noexcept
        {
-               using TableType = typename decltype(column)::TableType;
-               if (this->table.find(TableType())) {
+               using ColumnType = typename std::decay<Column>::type;
+               using TableType = typename ColumnType::TableType;
+               if (this->table.compare(TableType())) {
                        auto cname = this->table.getColumnName(column.type);
                        return this->table.name + "." + cname;
                }
 
-               return Base::template getColumnName<Column>(column);
+               return Base::template getColumnName<Column>(std::forward<Column>(column));
        }
 
 private:
index 7d8fdac634b7fb318a98c3e289e171683745d81d..7133f6c0636a37340ce1845e9a0cc772701ee2a7 100644 (file)
@@ -56,7 +56,7 @@ private:
        using ColumnNames = std::vector<std::string>;
        using TableNames = std::set<std::string>;
 
-       explicit Database(const std::string& name, ImplType impl);
+       explicit Database(const std::string& name, ImplType&& impl);
 
        template<typename ...Ts>
        friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
@@ -120,8 +120,8 @@ Database<Tables...> make_database(const std::string& name, Tables&& ...tables)
 }
 
 template<typename ...Tables>
-Database<Tables...>::Database(const std::string& name, ImplType impl)
-       : name(name), impl(impl) {}
+Database<Tables...>::Database(const std::string& name, ImplType&& impl)
+       : name(name), impl(std::move(impl)) {}
 
 template<typename... Tables>
 template<typename... ColumnTypes>
index 02540f8eec44341e554225aece14c0d93534bcf8..cee3642a8fb00dc2c902b14e6f461016dccab3d9 100644 (file)
@@ -30,7 +30,7 @@ public:
        std::vector<std::string> getColumnNames() const noexcept { return {}; }
 
        template<class Type>
-       std::string getColumnName(Type type) const noexcept { return std::string(); }
+       std::string getColumnName(Type&&) const noexcept { return std::string(); }
 
        int size() const noexcept { return 0; }
 };
@@ -41,7 +41,8 @@ public:
        using Column = Front;
        using TableType = typename Column::TableType;
 
-       explicit TableImpl(Front front, Rest ...rest) : Base(rest...), column(front) {}
+       explicit TableImpl(Front&& front, Rest&& ...rest) :
+               Base(std::forward<Rest>(rest)...), column(front) {}
 
        int size() const noexcept { return Base::size() + 1; }
 
@@ -53,12 +54,12 @@ public:
        }
 
        template<typename ColumnType>
-       std::string getColumnName(ColumnType type) const noexcept
+       std::string getColumnName(ColumnType&& type) const noexcept
        {
-               if (type::cast_compare(column.type, type))
+               if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
                        return column.name;
 
-               return Base::template getColumnName<ColumnType>(type);
+               return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(type));
        }
 
 private:
index db4364cc756ec24e61b9afcc53dbc189b3edcaa9..68cfff1606384bb31a1999ee20397db2c422b73e 100644 (file)
@@ -55,8 +55,8 @@ public:
        template<typename Expr>
        Self where(Expr expr);
 
-       template<typename Column>
-       bool find(Column column);
+       template<typename That>
+       bool compare(const That& that) const noexcept;
 
        operator std::string();
 
@@ -66,7 +66,7 @@ public:
        std::string name;
 
 private:
-       explicit Table(const std::string& name, ImplType impl);
+       explicit Table(const std::string& name, ImplType&& impl);
 
        template<typename ...Cs>
        friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
@@ -117,8 +117,8 @@ Table<Columns...> make_table(const std::string& name, Columns&& ...cs)
 }
 
 template<typename... Columns>
-Table<Columns...>::Table(const std::string& name, ImplType impl)
-       : name(name), impl(impl) {} 
+Table<Columns...>::Table(const std::string& name, ImplType&& impl)
+       : name(name), impl(std::move(impl)) {}
 
 template<typename... Columns>
 template<typename... ColumnTypes>
@@ -280,10 +280,10 @@ Table<Columns...>::operator std::string()
 
 template<typename... Columns>
 template<typename That>
-bool Table<Columns...>::find(That that)
+bool Table<Columns...>::compare(const That& that) const noexcept
 {
        using This = TableType;
-       return type::compare(This(), That());
+       return type::compare(This(), that);
 }
 
 template<typename... Columns>