From e1b841f5bd937f4676a6878ec2e7ef66b28bc719 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Sep 2025 16:27:43 +0200 Subject: [PATCH] Use unique_ptr<> for connection_pool::pimpl_ Also don't duplicate connection_pool ctor and dtor in POSIX and Windows branches as they are exactly the same for both of them. No real changes. --- include/soci/connection-pool.h | 3 ++- src/core/connection-pool.cpp | 27 +++++++-------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/include/soci/connection-pool.h b/include/soci/connection-pool.h index bd1ffe52..29d3b2c1 100644 --- a/include/soci/connection-pool.h +++ b/include/soci/connection-pool.h @@ -11,6 +11,7 @@ #include "soci/soci-platform.h" // std #include +#include namespace soci { @@ -31,7 +32,7 @@ public: private: struct connection_pool_impl; - connection_pool_impl * pimpl_; + std::unique_ptr pimpl_; SOCI_NOT_COPYABLE(connection_pool) }; diff --git a/src/core/connection-pool.cpp b/src/core/connection-pool.cpp index 2b456f22..82dc5f4b 100644 --- a/src/core/connection-pool.cpp +++ b/src/core/connection-pool.cpp @@ -98,16 +98,6 @@ struct connection_pool::connection_pool_impl : connection_pool_base_impl pthread_cond_t cond_; }; -connection_pool::connection_pool(std::size_t size) -{ - pimpl_ = new connection_pool_impl(size); -} - -connection_pool::~connection_pool() -{ - delete pimpl_; -} - bool connection_pool::try_lease(std::size_t & pos, int timeout) { struct timespec tm; @@ -242,16 +232,6 @@ struct connection_pool::connection_pool_impl : connection_pool_base_impl HANDLE sem_; }; -connection_pool::connection_pool(std::size_t size) -{ - pimpl_ = new connection_pool_impl(size); -} - -connection_pool::~connection_pool() -{ - delete pimpl_; -} - bool connection_pool::try_lease(std::size_t & pos, int timeout) { DWORD cc = WaitForSingleObject(pimpl_->sem_, @@ -308,6 +288,13 @@ void connection_pool::give_back(std::size_t pos) #endif // _WIN32 +connection_pool::connection_pool(std::size_t size) + : pimpl_(std::make_unique(size)) +{ +} + +connection_pool::~connection_pool() = default; + session & connection_pool::at(std::size_t pos) { if (pos >= pimpl_->sessions_.size())