mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
dbms: Server: Fixes. Fix for PODArray::swap(). [#METR-18844]
This commit is contained in:
parent
b1079964da
commit
a2e3c88dee
@ -166,54 +166,12 @@ public:
|
|||||||
|
|
||||||
PODArray(PODArray && other)
|
PODArray(PODArray && other)
|
||||||
{
|
{
|
||||||
if (other.isInitialized() && other.isAllocatedFromStack())
|
this->swap(other);
|
||||||
{
|
|
||||||
alloc(other.allocated_size());
|
|
||||||
memcpy(c_start, other.c_start, byte_size(other.size()));
|
|
||||||
c_end = c_start + (other.c_end - other.c_start);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c_start = other.c_start;
|
|
||||||
c_end = other.c_end;
|
|
||||||
c_end_of_storage = other.c_end_of_storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
other.c_start = nullptr;
|
|
||||||
other.c_end = nullptr;
|
|
||||||
other.c_end_of_storage = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PODArray & operator=(PODArray && other)
|
PODArray & operator=(PODArray && other)
|
||||||
{
|
{
|
||||||
if (other.isInitialized() && other.isAllocatedFromStack())
|
this->swap(other);
|
||||||
{
|
|
||||||
dealloc();
|
|
||||||
alloc(other.allocated_size());
|
|
||||||
memcpy(c_start, other.c_start, byte_size(other.size()));
|
|
||||||
c_end = c_start + (other.c_end - other.c_start);
|
|
||||||
|
|
||||||
other.c_start = nullptr;
|
|
||||||
other.c_end = nullptr;
|
|
||||||
other.c_end_of_storage = nullptr;
|
|
||||||
}
|
|
||||||
else if (isInitialized() && isAllocatedFromStack())
|
|
||||||
{
|
|
||||||
c_start = other.c_start;
|
|
||||||
c_end = other.c_end;
|
|
||||||
c_end_of_storage = other.c_end_of_storage;
|
|
||||||
|
|
||||||
other.c_start = nullptr;
|
|
||||||
other.c_end = nullptr;
|
|
||||||
other.c_end_of_storage = nullptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::swap(c_start, other.c_start);
|
|
||||||
std::swap(c_end, other.c_end);
|
|
||||||
std::swap(c_end_of_storage, other.c_end_of_storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,16 +338,37 @@ public:
|
|||||||
arr2.c_end = arr2.c_start + byte_size(stack_size);
|
arr2.c_end = arr2.c_start + byte_size(stack_size);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto do_move = [](PODArray & src, PODArray & dest)
|
||||||
|
{
|
||||||
|
if (src.isAllocatedFromStack())
|
||||||
|
{
|
||||||
|
dest.dealloc();
|
||||||
|
dest.alloc(src.allocated_size());
|
||||||
|
memcpy(dest.c_start, src.c_start, byte_size(src.size()));
|
||||||
|
dest.c_end = dest.c_start + (src.c_end - src.c_start);
|
||||||
|
|
||||||
|
src.c_start = nullptr;
|
||||||
|
src.c_end = nullptr;
|
||||||
|
src.c_end_of_storage = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::swap(dest.c_start, src.c_start);
|
||||||
|
std::swap(dest.c_end, src.c_end);
|
||||||
|
std::swap(dest.c_end_of_storage, src.c_end_of_storage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!isInitialized() && !rhs.isInitialized())
|
if (!isInitialized() && !rhs.isInitialized())
|
||||||
return;
|
return;
|
||||||
else if (!isInitialized() && rhs.isInitialized())
|
else if (!isInitialized() && rhs.isInitialized())
|
||||||
{
|
{
|
||||||
*this = std::move(rhs);
|
do_move(rhs, *this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (isInitialized() && !rhs.isInitialized())
|
else if (isInitialized() && !rhs.isInitialized())
|
||||||
{
|
{
|
||||||
rhs = std::move(*this);
|
do_move(*this, rhs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user