Browse Source

Simplify LinkedList data creation

tags/1.9.4
falkTX 10 years ago
parent
commit
2c01f078e9
2 changed files with 33 additions and 46 deletions
  1. +31
    -23
      source/utils/LinkedList.hpp
  2. +2
    -23
      source/utils/RtLinkedList.hpp

+ 31
- 23
source/utils/LinkedList.hpp View File

@@ -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);


+ 2
- 23
source/utils/RtLinkedList.hpp View File

@@ -158,29 +158,8 @@ private:
{
if (typename AbstractLinkedList<T>::Data* const data = _allocate_sleepy())
{
if (this->fNeedsCopyCtr)
{
try {
new(data)typename AbstractLinkedList<T>::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);


Loading…
Cancel
Save