From 4ca3211d3156aa3479c2a1b971b25f3c690b8122 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 17 Mar 2022 19:45:31 +0000 Subject: Lots of pass by value and perfect forwarding optimisations --- libdbpp/column.h | 8 +++---- libdbpp/command.h | 6 ++--- libdbpp/connection.cpp | 2 +- libdbpp/connection.h | 2 +- libdbpp/mockDatabase.h | 7 +++--- libdbpp/selectcommandUtil.impl.h | 4 ++-- libdbpp/tablepatch.cpp | 13 ++++++----- libdbpp/testCore.cpp | 43 ++++++++++++++++++------------------ libdbpp/testCore.h | 4 ++-- libdbpp/unittests/libdbpp-mysql | 2 +- libdbpp/unittests/libdbpp-odbc | 2 +- libdbpp/unittests/libdbpp-postgresql | 2 +- libdbpp/unittests/libdbpp-sqlite | 2 +- 13 files changed, 50 insertions(+), 47 deletions(-) diff --git a/libdbpp/column.h b/libdbpp/column.h index a30e1b8..b9260cb 100644 --- a/libdbpp/column.h +++ b/libdbpp/column.h @@ -42,9 +42,9 @@ namespace DB { /// The field is floating point/fixed point/numeric. virtual void floatingpoint(double) = 0; /// The field is an interval/duration/time span. - virtual void interval(const boost::posix_time::time_duration &) = 0; + virtual void interval(const boost::posix_time::time_duration) = 0; /// The field is a timestamp/date/datetime. - virtual void timestamp(const boost::posix_time::ptime &) = 0; + virtual void timestamp(const boost::posix_time::ptime) = 0; /// The field is a BLOB. virtual void blob(const Blob &); }; @@ -100,12 +100,12 @@ namespace DB { (*this)(v); } void - timestamp(const boost::posix_time::ptime & v) override + timestamp(const boost::posix_time::ptime v) override { (*this)(v); } void - interval(const boost::posix_time::time_duration & v) override + interval(const boost::posix_time::time_duration v) override { (*this)(v); } diff --git a/libdbpp/command.h b/libdbpp/command.h index eae7775..98e59b4 100644 --- a/libdbpp/command.h +++ b/libdbpp/command.h @@ -100,7 +100,7 @@ namespace DB { /// Bind a string to parameter i. virtual void bindParamS(unsigned int i, const Glib::ustring &) = 0; /// Bind a string_view to parameter i. - virtual void bindParamS(unsigned int i, const std::string_view &) = 0; + virtual void bindParamS(unsigned int i, const std::string_view) = 0; /// Bind a string to parameter i (wraps string_view). inline void bindParamS(unsigned int i, const std::string & v) @@ -109,9 +109,9 @@ namespace DB { } /// Bind a duration to parameter i. - virtual void bindParamT(unsigned int i, const boost::posix_time::time_duration &) = 0; + virtual void bindParamT(unsigned int i, const boost::posix_time::time_duration) = 0; /// Bind a date time to parameter i. - virtual void bindParamT(unsigned int i, const boost::posix_time::ptime &) = 0; + virtual void bindParamT(unsigned int i, const boost::posix_time::ptime) = 0; /// Bind a BLOB to parameter i. virtual void bindParamBLOB(unsigned int i, const Blob &); diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 7d3db42..7208c93 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -162,7 +162,7 @@ DB::Connection::bulkUploadData(FILE * in) const AdHocFormatter(PluginLibraryFormat, "libdbpp-%?.so"); std::optional -DB::Connection::resolvePlugin(const std::type_info &, const std::string_view & name) +DB::Connection::resolvePlugin(const std::type_info &, const std::string_view name) { return PluginLibraryFormat::get(name); } diff --git a/libdbpp/connection.h b/libdbpp/connection.h index 8bf74af..4399b37 100644 --- a/libdbpp/connection.h +++ b/libdbpp/connection.h @@ -145,7 +145,7 @@ namespace DB { PatchResult patchTable(TablePatch * tp); /// AdHoc plugin resolver helper for database connectors. - static std::optional resolvePlugin(const std::type_info &, const std::string_view &); + static std::optional resolvePlugin(const std::type_info &, const std::string_view); protected: /// Create a new connection. diff --git a/libdbpp/mockDatabase.h b/libdbpp/mockDatabase.h index 55c175f..d067967 100644 --- a/libdbpp/mockDatabase.h +++ b/libdbpp/mockDatabase.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include // IWYU pragma: no_include "factory.impl.h" @@ -68,11 +69,11 @@ namespace DB { /// @param s the collection of scripts to populate the mock database. /// @param args arguments to the mock database constructor. template - PluginMock(const std::string & name, const std::initializer_list & s, - const Args &... args) : + PluginMock(const std::string & name, const std::initializer_list & s, Args &&... args) : mockName(name) { - AdHoc::PluginManager::getDefault()->create(mockName, __FILE__, __LINE__, args..., name, s); + AdHoc::PluginManager::getDefault()->create( + mockName, __FILE__, __LINE__, std::forward(args)..., name, s); } ~PluginMock() { diff --git a/libdbpp/selectcommandUtil.impl.h b/libdbpp/selectcommandUtil.impl.h index ec1d56a..9ef901e 100644 --- a/libdbpp/selectcommandUtil.impl.h +++ b/libdbpp/selectcommandUtil.impl.h @@ -8,11 +8,11 @@ namespace DB { template inline void - forEachField(DB::SelectCommand * sel, const Func & func, const Args &... args) + forEachField(DB::SelectCommand * sel, const Func & func, Args &&... args) { if constexpr (field >= std::tuple_size::value) { (void)sel; - func(args...); + func(std::forward(args)...); } else { typename std::tuple_element::type a; diff --git a/libdbpp/tablepatch.cpp b/libdbpp/tablepatch.cpp index 132e28c..db8cac6 100644 --- a/libdbpp/tablepatch.cpp +++ b/libdbpp/tablepatch.cpp @@ -8,6 +8,7 @@ #include #include #include +#include DB::PatchResult DB::Connection::patchTable(TablePatch * tp) @@ -41,17 +42,17 @@ push(const boost::format &, typename Container::const_iterator &) template static inline void -push(boost::format & f, typename Container::const_iterator & i, const Value & v, const Values &... vs) +push(boost::format & f, typename Container::const_iterator & i, const Value & v, Values &&... vs) { f % v(i); - push(f, i, vs...); + push(f, i, std::forward(vs)...); } template static inline unsigned int appendIf(AdHoc::Buffer & buf, const Container & c, const std::function & sel, const Separator & sep, - const std::string & fmts, const Ps &... ps) + const std::string & fmts, Ps &&... ps) { auto fmt = AdHoc::Buffer::getFormat(fmts); unsigned int x = 0; @@ -60,7 +61,7 @@ appendIf(AdHoc::Buffer & buf, const Container & c, if (x > 0) { buf.appendbf("%s", sep); } - push(fmt, i, ps...); + push(fmt, i, std::forward(ps)...); buf.append(fmt.str()); x += 1; } @@ -70,14 +71,14 @@ appendIf(AdHoc::Buffer & buf, const Container & c, template static inline unsigned int -append(AdHoc::Buffer & buf, const Container & c, const Separator & sep, const std::string & fmts, const Ps &... ps) +append(AdHoc::Buffer & buf, const Container & c, const Separator & sep, const std::string & fmts, Ps &&... ps) { return appendIf( buf, c, [](auto) { return true; }, - sep, fmts, ps...); + sep, fmts, std::forward(ps)...); } template diff --git a/libdbpp/testCore.cpp b/libdbpp/testCore.cpp index 94e1cbf..ef2588d 100644 --- a/libdbpp/testCore.cpp +++ b/libdbpp/testCore.cpp @@ -44,12 +44,12 @@ namespace DB { (*this)(v); } void - timestamp(const boost::posix_time::ptime & v) override + timestamp(const boost::posix_time::ptime v) override { (*this)(v); } void - interval(const boost::posix_time::time_duration & v) override + interval(const boost::posix_time::time_duration v) override { (*this)(v); } @@ -82,8 +82,9 @@ namespace DB { template void - TestCore::assertScalarValueHelper(DB::SelectCommand & sel, const T & t) const + TestCore::assertScalarValueHelper(DB::SelectCommand & sel, const T t) const { + static_assert(std::is_trivially_copyable_v); while (sel.fetch()) { assertColumnValueHelper(sel, 0, t); } @@ -91,8 +92,9 @@ namespace DB { template void - TestCore::assertColumnValueHelper(DB::SelectCommand & sel, unsigned int col, const T & t) const + TestCore::assertColumnValueHelper(DB::SelectCommand & sel, unsigned int col, const T t) const { + static_assert(std::is_trivially_copyable_v); Assert a(t); sel[col].apply(a); } @@ -105,27 +107,26 @@ namespace DB { return s; } - template void TestCore::assertScalarValueHelper(SelectCommand &, const bool &) const; - template void TestCore::assertScalarValueHelper(SelectCommand &, const int64_t &) const; - template void TestCore::assertScalarValueHelper(SelectCommand &, const int &) const; - template void TestCore::assertScalarValueHelper(SelectCommand &, const double &) const; - template void TestCore::assertScalarValueHelper(SelectCommand &, const std::string_view &) const; + template void TestCore::assertScalarValueHelper(SelectCommand &, const bool) const; + template void TestCore::assertScalarValueHelper(SelectCommand &, const int64_t) const; + template void TestCore::assertScalarValueHelper(SelectCommand &, const int) const; + template void TestCore::assertScalarValueHelper(SelectCommand &, const double) const; + template void TestCore::assertScalarValueHelper(SelectCommand &, const std::string_view) const; template void TestCore::assertScalarValueHelper( - SelectCommand &, const boost::posix_time::ptime &) const; + SelectCommand &, const boost::posix_time::ptime) const; template void TestCore::assertScalarValueHelper( - SelectCommand &, const boost::posix_time::time_duration &) const; - template void TestCore::assertScalarValueHelper(SelectCommand &, const DB::Blob &) const; + SelectCommand &, const boost::posix_time::time_duration) const; + template void TestCore::assertScalarValueHelper(SelectCommand &, const DB::Blob) const; - template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const bool &) const; - template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const int &) const; - template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const int64_t &) const; - template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const double &) const; + template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const bool) const; + template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const int) const; + template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const int64_t) const; + template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const double) const; template void TestCore::assertColumnValueHelper( - SelectCommand &, unsigned int, const std::string_view &) const; + SelectCommand &, unsigned int, const std::string_view) const; template void TestCore::assertColumnValueHelper( - SelectCommand &, unsigned int, const boost::posix_time::ptime &) const; + SelectCommand &, unsigned int, const boost::posix_time::ptime) const; template void TestCore::assertColumnValueHelper( - SelectCommand &, unsigned int, const boost::posix_time::time_duration &) const; - template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const DB::Blob &) const; - + SelectCommand &, unsigned int, const boost::posix_time::time_duration) const; + template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const DB::Blob) const; } diff --git a/libdbpp/testCore.h b/libdbpp/testCore.h index 32c033d..16c4999 100644 --- a/libdbpp/testCore.h +++ b/libdbpp/testCore.h @@ -27,8 +27,8 @@ namespace DB { std::vector testBlobData; DB::Blob testBlob; - template void assertScalarValueHelper(SelectCommand & sel, const T & t) const; - template void assertColumnValueHelper(SelectCommand & sel, unsigned int col, const T & t) const; + template void assertScalarValueHelper(SelectCommand & sel, const T t) const; + template void assertColumnValueHelper(SelectCommand & sel, unsigned int col, const T t) const; }; /// @endcond diff --git a/libdbpp/unittests/libdbpp-mysql b/libdbpp/unittests/libdbpp-mysql index ce5d5f8..aae2742 160000 --- a/libdbpp/unittests/libdbpp-mysql +++ b/libdbpp/unittests/libdbpp-mysql @@ -1 +1 @@ -Subproject commit ce5d5f847b07d980a6042fd4ef14bc80154b6c02 +Subproject commit aae2742b9dbc2a5908459372d75e11a0fdec5cb5 diff --git a/libdbpp/unittests/libdbpp-odbc b/libdbpp/unittests/libdbpp-odbc index 40ad9a3..704dd8c 160000 --- a/libdbpp/unittests/libdbpp-odbc +++ b/libdbpp/unittests/libdbpp-odbc @@ -1 +1 @@ -Subproject commit 40ad9a3711e703fde3d78a5633e42113cb450705 +Subproject commit 704dd8c7ecedb68161c52329e22141877143ff13 diff --git a/libdbpp/unittests/libdbpp-postgresql b/libdbpp/unittests/libdbpp-postgresql index 26e6666..d6fd5db 160000 --- a/libdbpp/unittests/libdbpp-postgresql +++ b/libdbpp/unittests/libdbpp-postgresql @@ -1 +1 @@ -Subproject commit 26e6666d48d0c2e467603f07b60b91f825c55342 +Subproject commit d6fd5db66afb2493202192c018cdb153f0a1ca84 diff --git a/libdbpp/unittests/libdbpp-sqlite b/libdbpp/unittests/libdbpp-sqlite index 045b8eb..8f00ea3 160000 --- a/libdbpp/unittests/libdbpp-sqlite +++ b/libdbpp/unittests/libdbpp-sqlite @@ -1 +1 @@ -Subproject commit 045b8ebd2234ee5b356f0b9cc6ba54cf1e57685b +Subproject commit 8f00ea37def4d0f3d36d77ec643a9abd193161b2 -- cgit v1.2.3