From d40dcd28f32316aca8d55005c917dc7652a4c423 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Thu, 16 Apr 2020 17:53:21 +0100 Subject: [PATCH] removed uneeded swap method --- lib/include/srslte/common/move_callback.h | 45 ++++++----------------- lib/test/common/queue_test.cc | 2 +- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/lib/include/srslte/common/move_callback.h b/lib/include/srslte/common/move_callback.h index 70dcd153e..fd7686b77 100644 --- a/lib/include/srslte/common/move_callback.h +++ b/lib/include/srslte/common/move_callback.h @@ -39,28 +39,29 @@ template class oper_table_t { public: - constexpr oper_table_t(bool in_buffer_) : is_in_buffer(in_buffer_) {} + constexpr oper_table_t() = default; virtual R call(void* src, Args&&... args) const = 0; virtual void move(void* src, void* dest) const = 0; virtual void dtor(void* src) const = 0; - bool is_in_buffer; + virtual bool is_in_small_buffer() const = 0; }; template class empty_table_t : public oper_table_t { public: - constexpr empty_table_t() : oper_table_t(true) {} + constexpr empty_table_t() = default; R call(void* src, Args&&... args) const final { throw std::bad_function_call(); } void move(void* src, void* dest) const final {} void dtor(void* src) const final {} + bool is_in_small_buffer() const final { return true; } }; template class smallbuffer_table_t : public oper_table_t { public: - constexpr smallbuffer_table_t() : oper_table_t(true) {} + constexpr smallbuffer_table_t() = default; R call(void* src, Args&&... args) const final { return (*static_cast(src))(std::forward(args)...); } void move(void* src, void* dest) const final { @@ -68,13 +69,14 @@ public: static_cast(src)->~FunT(); } void dtor(void* src) const final { static_cast(src)->~FunT(); } + bool is_in_small_buffer() const final { return true; } }; template class heap_table_t : public oper_table_t { public: - constexpr heap_table_t() : oper_table_t(false) {} + constexpr heap_table_t() = default; R call(void* src, Args&&... args) const final { return (**static_cast(src))(std::forward(args)...); } void move(void* src, void* dest) const final { @@ -82,6 +84,7 @@ public: *static_cast(src) = nullptr; } void dtor(void* src) const final { delete (*static_cast(src)); } + bool is_in_small_buffer() const final { return false; } }; //! Metafunction to check if object is move_callback<> type @@ -93,10 +96,10 @@ struct is_move_callback > : std::true_type {}; //! metafunctions to enable/disable functions based on whether the callback fits small buffer or not template ::type> using enable_if_small_capture = - typename std::enable_if::value, bool>::type; + typename std::enable_if::value, bool>::type; template ::type> using enable_if_big_capture = - typename std::enable_if < Cap::value, bool>::type; + typename std::enable_if < Cap::value, bool>::type; } // namespace task_details @@ -149,33 +152,7 @@ public: R operator()(Args&&... args) const noexcept { return oper_ptr->call(&buffer, std::forward(args)...); } bool is_empty() const { return oper_ptr == empty_table; } - bool is_in_small_buffer() const { return oper_ptr->is_in_buffer; } - - void swap(move_callback& other) noexcept - { - if (this == &other) - return; - - if (oper_ptr->is_in_buffer and other.oper_ptr->is_in_buffer) { - storage_t tmp; - oper_ptr->move(&buffer, &tmp); - other.oper_ptr->move(&other.buffer, &buffer); - oper_ptr->move(&tmp, &other.buffer); - } else if (oper_ptr->is_in_buffer and not other.oper_ptr->is_in_buffer) { - void* tmpptr = other.ptr; - oper_ptr->move(&buffer, &other.buffer); - ptr = tmpptr; - } else if (not oper_ptr->is_in_buffer and other.oper_ptr->is_in_buffer) { - void* tmpptr = ptr; - other.oper_ptr->move(&other.buffer, &buffer); - other.ptr = tmpptr; - } else { - std::swap(ptr, other.ptr); - } - std::swap(oper_ptr, other.oper_ptr); - } - - friend void swap(move_callback& lhs, move_callback& rhs) noexcept { lhs.swap(rhs); } + bool is_in_small_buffer() const { return oper_ptr->is_in_small_buffer(); } private: union { diff --git a/lib/test/common/queue_test.cc b/lib/test/common/queue_test.cc index 189540689..17c6ce8e6 100644 --- a/lib/test/common/queue_test.cc +++ b/lib/test/common/queue_test.cc @@ -383,7 +383,7 @@ int test_inplace_task() t2(); TESTASSERT(v == 6); TESTASSERT(t.is_in_small_buffer() and not t2.is_in_small_buffer()); - swap(t, t2); + std::swap(t, t2); TESTASSERT(t2.is_in_small_buffer() and not t.is_in_small_buffer()); v = 0; t();