From 64da638ee700fba2d51eabc6a2e070adef823a12 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 17 Jul 2024 18:42:07 +0200 Subject: bptr: factor out common code out of .inl --- compat/borrowed-ptr.cpp | 2 ++ compat/borrowed-ptr.inl | 13 +++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/compat/borrowed-ptr.cpp b/compat/borrowed-ptr.cpp index 1dded12a..e64468d5 100644 --- a/compat/borrowed-ptr.cpp +++ b/compat/borrowed-ptr.cpp @@ -4,6 +4,8 @@ namespace floormat::detail_bptr { void control_block::decrement(control_block*& blk) noexcept { + if (!blk) + return; auto c2 = --blk->_hard_count; fm_bptr_assert(c2 != (uint32_t)-1); if (c2 == 0) diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index e1a5f591..2ae1226b 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -9,7 +9,7 @@ namespace floormat { -template bptr::~bptr() noexcept { if (blk) detail_bptr::control_block::decrement(blk); } +template bptr::~bptr() noexcept { detail_bptr::control_block::decrement(blk); } template bptr::bptr(const bptr>& ptr) noexcept requires std::is_const_v: bptr{ptr, nullptr} {} template bptr::bptr(bptr>&& ptr) noexcept requires std::is_const_v: bptr{move(ptr), nullptr} {} @@ -41,14 +41,13 @@ template Y> bptr& bptr::operator=(bptr&& other) noexcept { return _move_assign(move(other)); } -template void bptr::reset() noexcept { if (blk) detail_bptr::control_block::decrement(blk); } +template void bptr::reset() noexcept { detail_bptr::control_block::decrement(blk); } template template Y> void bptr::reset(Y* ptr) noexcept { - if (blk) - detail_bptr::control_block::decrement(blk); + detail_bptr::control_block::decrement(blk); blk = ptr ? new detail_bptr::control_block{const_cast*>(ptr), 1, #ifndef FM_NO_WEAK_BPTR 1, @@ -95,8 +94,7 @@ bptr& bptr::_copy_assign(const bptr& other) noexcept { if (blk != other.blk) { - if (blk) - detail_bptr::control_block::decrement(blk); + detail_bptr::control_block::decrement(blk); blk = other.blk; if (blk) { @@ -113,8 +111,7 @@ template template bptr& bptr::_move_assign(bptr&& other) noexcept { - if (blk) - detail_bptr::control_block::decrement(blk); + detail_bptr::control_block::decrement(blk); blk = other.blk; other.blk = nullptr; return *this; -- cgit v1.2.3