mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
PODArray swap fix
This commit is contained in:
parent
289712f19d
commit
12e411f8b9
@ -568,7 +568,7 @@ public:
|
||||
|
||||
/// arr1 takes ownership of the heap memory of arr2.
|
||||
arr1.c_start = arr2.c_start;
|
||||
arr1.c_end_of_storage = arr1.c_start + heap_allocated - arr1.pad_right;
|
||||
arr1.c_end_of_storage = arr1.c_start + heap_allocated - arr2.pad_right - arr2.pad_left;
|
||||
arr1.c_end = arr1.c_start + this->byte_size(heap_size);
|
||||
|
||||
/// Allocate stack space for arr2.
|
||||
@ -585,7 +585,7 @@ public:
|
||||
dest.dealloc();
|
||||
dest.alloc(src.allocated_bytes(), std::forward<TAllocatorParams>(allocator_params)...);
|
||||
memcpy(dest.c_start, src.c_start, this->byte_size(src.size()));
|
||||
dest.c_end = dest.c_start + (src.c_end - src.c_start);
|
||||
dest.c_end = dest.c_start + this->byte_size(src.size());
|
||||
|
||||
src.c_start = Base::null;
|
||||
src.c_end = Base::null;
|
||||
@ -597,6 +597,11 @@ public:
|
||||
std::swap(dest.c_end, src.c_end);
|
||||
std::swap(dest.c_end_of_storage, src.c_end_of_storage);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
this->protect();
|
||||
rhs.protect();
|
||||
#endif
|
||||
};
|
||||
|
||||
if (!this->isInitialized() && !rhs.isInitialized())
|
||||
@ -639,8 +644,8 @@ public:
|
||||
size_t rhs_size = rhs.size();
|
||||
size_t rhs_allocated = rhs.allocated_bytes();
|
||||
|
||||
this->c_end_of_storage = this->c_start + rhs_allocated - Base::pad_right;
|
||||
rhs.c_end_of_storage = rhs.c_start + lhs_allocated - Base::pad_right;
|
||||
this->c_end_of_storage = this->c_start + rhs_allocated - Base::pad_right - Base::pad_left;
|
||||
rhs.c_end_of_storage = rhs.c_start + lhs_allocated - Base::pad_right - Base::pad_left;
|
||||
|
||||
this->c_end = this->c_start + this->byte_size(rhs_size);
|
||||
rhs.c_end = rhs.c_start + this->byte_size(lhs_size);
|
||||
@ -659,6 +664,11 @@ public:
|
||||
std::swap(this->c_end, rhs.c_end);
|
||||
std::swap(this->c_end_of_storage, rhs.c_end_of_storage);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
this->protect();
|
||||
rhs.protect();
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename... TAllocatorParams>
|
||||
@ -693,34 +703,34 @@ public:
|
||||
}
|
||||
|
||||
|
||||
bool operator== (const PODArray & other) const
|
||||
bool operator== (const PODArray & rhs) const
|
||||
{
|
||||
if (this->size() != other.size())
|
||||
if (this->size() != rhs.size())
|
||||
return false;
|
||||
|
||||
const_iterator this_it = begin();
|
||||
const_iterator that_it = other.begin();
|
||||
const_iterator lhs_it = begin();
|
||||
const_iterator rhs_it = rhs.begin();
|
||||
|
||||
while (this_it != end())
|
||||
while (lhs_it != end())
|
||||
{
|
||||
if (*this_it != *that_it)
|
||||
if (*lhs_it != *rhs_it)
|
||||
return false;
|
||||
|
||||
++this_it;
|
||||
++that_it;
|
||||
++lhs_it;
|
||||
++rhs_it;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!= (const PODArray & other) const
|
||||
bool operator!= (const PODArray & rhs) const
|
||||
{
|
||||
return !operator==(other);
|
||||
return !operator==(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, size_t initial_bytes, typename TAllocator, size_t pad_right_>
|
||||
void swap(PODArray<T, initial_bytes, TAllocator, pad_right_> & lhs, PODArray<T, initial_bytes, TAllocator, pad_right_> & rhs)
|
||||
template <typename T, size_t initial_bytes, typename TAllocator, size_t pad_right_, size_t pad_left_>
|
||||
void swap(PODArray<T, initial_bytes, TAllocator, pad_right_, pad_left_> & lhs, PODArray<T, initial_bytes, TAllocator, pad_right_, pad_left_> & rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user