diff --git a/source/utils/LinkedList.hpp b/source/utils/LinkedList.hpp index 0569283f1..1f14e35a3 100644 --- a/source/utils/LinkedList.hpp +++ b/source/utils/LinkedList.hpp @@ -352,6 +352,35 @@ protected: virtual Data* _allocate() noexcept = 0; virtual void _deallocate(Data* const dataPtr) noexcept = 0; + bool _createData(Data* const data, const T& value) + { + if (fNeedsCopyCtr) + { + try { + new(data)Data(); + } + catch(...) { + _deallocate(data); + return false; + } + + try { + data->value = value; + } + catch(...) { + data->~Data(); + _deallocate(data); + return false; + } + } + else + { + std::memcpy(&data->value, &value, this->fDataSize); + } + + return true; + } + private: mutable T fRetValue; @@ -365,29 +394,8 @@ private: { if (Data* const data = _allocate()) { - if (fNeedsCopyCtr) - { - try { - new(data)Data(); - } - catch(...) { - _deallocate(data); - return false; - } - - try { - data->value = value; - } - catch(...) { - data->~Data(); - _deallocate(data); - return false; - } - } - else - { - std::memcpy(&data->value, &value, fDataSize); - } + if (! _createData(data, value)) + return false; if (inTail) list_add_tail(&data->siblings, queue); diff --git a/source/utils/RtLinkedList.hpp b/source/utils/RtLinkedList.hpp index 156f971a2..50868906f 100644 --- a/source/utils/RtLinkedList.hpp +++ b/source/utils/RtLinkedList.hpp @@ -158,29 +158,8 @@ private: { if (typename AbstractLinkedList::Data* const data = _allocate_sleepy()) { - if (this->fNeedsCopyCtr) - { - try { - new(data)typename AbstractLinkedList::Data(); - } - catch(...) { - _deallocate(data); - return false; - } - - try { - data->value = value; - } - catch(...) { - data->~Data(); - _deallocate(data); - return false; - } - } - else - { - std::memcpy(&data->value, &value, this->fDataSize); - } + if (! this->_createData(data, value)) + return false; if (inTail) list_add_tail(&data->siblings, &this->fQueue);