From 71a6d821544eb3516f7fb11b1f37cd30039cc541 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Fri, 17 Nov 2023 23:43:58 +0100 Subject: [PATCH] Move function wrapper --- include/tao/pq/connection.hpp | 8 ++++---- include/tao/pq/connection_pool.hpp | 8 ++++---- src/lib/pq/connection.cpp | 14 +++++++------- src/lib/pq/connection_pool.cpp | 14 +++++++------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/tao/pq/connection.hpp b/include/tao/pq/connection.hpp index 1c67486..aaa1595 100644 --- a/include/tao/pq/connection.hpp +++ b/include/tao/pq/connection.hpp @@ -99,7 +99,7 @@ namespace tao::pq }; public: - connection( const private_key /*unused*/, const std::string& connection_info, const std::function< poll::callback >& poll_cb ); + connection( const private_key /*unused*/, const std::string& connection_info, std::function< poll::callback > poll_cb ); connection( const connection& ) = delete; connection( connection&& ) = delete; @@ -108,12 +108,12 @@ namespace tao::pq ~connection() = default; - [[nodiscard]] static auto create( const std::string& connection_info, const std::function< poll::callback >& poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection >; + [[nodiscard]] static auto create( const std::string& connection_info, std::function< poll::callback > poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection >; [[nodiscard]] auto error_message() const -> std::string; - [[nodiscard]] auto poll_callback() const -> std::function< poll::callback >; - void set_poll_callback( const std::function< poll::callback >& poll_cb ); + [[nodiscard]] auto poll_callback() const noexcept -> const std::function< poll::callback >&; + void set_poll_callback( std::function< poll::callback > poll_cb ) noexcept; void reset_poll_callback(); [[nodiscard]] auto notification_handler() const -> std::function< void( const notification& ) >; diff --git a/include/tao/pq/connection_pool.hpp b/include/tao/pq/connection_pool.hpp index beed92f..e022106 100644 --- a/include/tao/pq/connection_pool.hpp +++ b/include/tao/pq/connection_pool.hpp @@ -43,9 +43,9 @@ namespace tao::pq }; public: - connection_pool( const private_key /*unused*/, const std::string_view connection_info, const std::function< poll::callback >& poll_cb ); + connection_pool( const private_key /*unused*/, const std::string_view connection_info, std::function< poll::callback > poll_cb ); - [[nodiscard]] static auto create( const std::string_view connection_info, const std::function< poll::callback >& poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection_pool >; + [[nodiscard]] static auto create( const std::string_view connection_info, std::function< poll::callback > poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection_pool >; [[nodiscard]] auto timeout() const noexcept -> decltype( auto ) { @@ -55,8 +55,8 @@ namespace tao::pq void set_timeout( const std::chrono::milliseconds timeout ) noexcept; void reset_timeout() noexcept; - [[nodiscard]] auto poll_callback() const -> std::function< poll::callback >; - void set_poll_callback( const std::function< poll::callback >& poll_cb ); + [[nodiscard]] auto poll_callback() const noexcept -> const std::function< poll::callback >&; + void set_poll_callback( std::function< poll::callback > poll_cb ) noexcept; void reset_poll_callback(); [[nodiscard]] auto connection() -> std::shared_ptr< connection >; diff --git a/src/lib/pq/connection.cpp b/src/lib/pq/connection.cpp index 5d4667c..d746d95 100644 --- a/src/lib/pq/connection.cpp +++ b/src/lib/pq/connection.cpp @@ -378,10 +378,10 @@ namespace tao::pq } } - connection::connection( const private_key /*unused*/, const std::string& connection_info, const std::function< poll::callback >& poll_cb ) + connection::connection( const private_key /*unused*/, const std::string& connection_info, std::function< poll::callback > poll_cb ) : m_pgconn( PQconnectdb( connection_info.c_str() ), &PQfinish ), m_current_transaction( nullptr ), - m_poll( poll_cb ) + m_poll( std::move( poll_cb ) ) { if( !is_open() ) { // note that we can not access the sqlstate after PQconnectdb(), @@ -394,9 +394,9 @@ namespace tao::pq } } - auto connection::create( const std::string& connection_info, const std::function< poll::callback >& poll_cb ) -> std::shared_ptr< connection > + auto connection::create( const std::string& connection_info, std::function< poll::callback > poll_cb ) -> std::shared_ptr< connection > { - return std::make_shared< connection >( private_key(), connection_info, poll_cb ); + return std::make_shared< connection >( private_key(), connection_info, std::move( poll_cb ) ); } auto connection::error_message() const -> std::string @@ -404,14 +404,14 @@ namespace tao::pq return PQerrorMessage( m_pgconn.get() ); } - auto connection::poll_callback() const -> std::function< poll::callback > + auto connection::poll_callback() const noexcept -> const std::function< poll::callback >& { return m_poll; } - void connection::set_poll_callback( const std::function< poll::callback >& poll_cb ) + void connection::set_poll_callback( std::function< poll::callback > poll_cb ) noexcept { - m_poll = poll_cb; + m_poll = std::move( poll_cb ); } void connection::reset_poll_callback() diff --git a/src/lib/pq/connection_pool.cpp b/src/lib/pq/connection_pool.cpp index 89dc6f6..abe9470 100644 --- a/src/lib/pq/connection_pool.cpp +++ b/src/lib/pq/connection_pool.cpp @@ -11,14 +11,14 @@ namespace tao::pq return std::make_unique< pq::connection >( pq::connection::private_key(), m_connection_info, m_poll ); } - connection_pool::connection_pool( const private_key /*unused*/, const std::string_view connection_info, const std::function< poll::callback >& poll_cb ) + connection_pool::connection_pool( const private_key /*unused*/, const std::string_view connection_info, std::function< poll::callback > poll_cb ) : m_connection_info( connection_info ), - m_poll( poll_cb ) + m_poll( std::move( poll_cb ) ) {} - auto connection_pool::create( const std::string_view connection_info, const std::function< poll::callback >& poll_cb ) -> std::shared_ptr< connection_pool > + auto connection_pool::create( const std::string_view connection_info, std::function< poll::callback > poll_cb ) -> std::shared_ptr< connection_pool > { - return std::make_shared< connection_pool >( private_key(), connection_info, poll_cb ); + return std::make_shared< connection_pool >( private_key(), connection_info, std::move( poll_cb ) ); } void connection_pool::set_timeout( const std::chrono::milliseconds timeout ) noexcept @@ -31,14 +31,14 @@ namespace tao::pq m_timeout = std::nullopt; } - auto connection_pool::poll_callback() const -> std::function< poll::callback > + auto connection_pool::poll_callback() const noexcept -> const std::function< poll::callback >& { return m_poll; } - void connection_pool::set_poll_callback( const std::function< poll::callback >& poll_cb ) + void connection_pool::set_poll_callback( std::function< poll::callback > poll_cb ) noexcept { - m_poll = poll_cb; + m_poll = std::move( poll_cb ); } void connection_pool::reset_poll_callback()