From d6fd5db66afb2493202192c018cdb153f0a1ca84 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 17 Mar 2022 19:45:15 +0000 Subject: Lots of pass by value and perfect forwarding optimisations --- libpqpp/pq-command.cpp | 13 +++++++------ libpqpp/pq-command.h | 10 +++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/libpqpp/pq-command.cpp b/libpqpp/pq-command.cpp index 9e98eb5..dad2ef9 100644 --- a/libpqpp/pq-command.cpp +++ b/libpqpp/pq-command.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace Glib { class ustring; @@ -69,17 +70,17 @@ PQ::Command::paramsAtLeast(unsigned int n) AdHocFormatter(PQCommandParamFmt, "%?"); template void -PQ::Command::paramSet(unsigned int n, const T &... v) +PQ::Command::paramSet(unsigned int n, T &&... v) { paramsAtLeast(n); - bufs[n] = std::make_unique(PQCommandParamFmt::get(v...)); + bufs[n] = std::make_unique(PQCommandParamFmt::get(std::forward(v)...)); lengths[n] = static_cast(bufs[n]->length()); formats[n] = 0; values[n] = bufs[n]->data(); } void -PQ::Command::paramSet(unsigned int n, const std::string_view & b) +PQ::Command::paramSet(unsigned int n, const std::string_view b) { paramsAtLeast(n); bufs[n] = std::make_unique(b); @@ -139,17 +140,17 @@ PQ::Command::bindParamS(unsigned int n, const Glib::ustring & s) paramSet(n, std::string_view(s.data(), s.bytes())); } void -PQ::Command::bindParamS(unsigned int n, const std::string_view & s) +PQ::Command::bindParamS(unsigned int n, const std::string_view s) { paramSet(n, s); } void -PQ::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration & v) +PQ::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration v) { paramSet(n, boost::posix_time::to_simple_string(v)); } void -PQ::Command::bindParamT(unsigned int n, const boost::posix_time::ptime & v) +PQ::Command::bindParamT(unsigned int n, const boost::posix_time::ptime v) { paramSet(n, boost::posix_time::to_iso_extended_string(v)); } diff --git a/libpqpp/pq-command.h b/libpqpp/pq-command.h index d187645..a99bd72 100644 --- a/libpqpp/pq-command.h +++ b/libpqpp/pq-command.h @@ -56,10 +56,10 @@ namespace PQ { void bindParamF(unsigned int, float) override; void bindParamS(unsigned int, const Glib::ustring &) override; - void bindParamS(unsigned int, const std::string_view &) override; + void bindParamS(unsigned int, const std::string_view) override; - void bindParamT(unsigned int, const boost::posix_time::time_duration &) override; - void bindParamT(unsigned int, const boost::posix_time::ptime &) override; + void bindParamT(unsigned int, const boost::posix_time::time_duration) override; + void bindParamT(unsigned int, const boost::posix_time::ptime) override; void bindParamBLOB(unsigned int, const DB::Blob &) override; @@ -72,8 +72,8 @@ namespace PQ { Connection * const c; void paramsAtLeast(unsigned int); - template void paramSet(unsigned int, const T &... t); - void paramSet(unsigned int, const std::string_view &); + template void paramSet(unsigned int, T &&... t); + void paramSet(unsigned int, const std::string_view); std::vector values; std::vector lengths; std::vector formats; -- cgit v1.2.3