Skip to content

Commit

Permalink
Fixes move behaviour of chunk container (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
rghouzra authored Nov 30, 2024
1 parent bbee306 commit 8597b4a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/XAD/ChunkContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,20 @@ class ChunkContainer
}

ChunkContainer(ChunkContainer&& o) noexcept
: chunkList_(std::move(o.chunkList_)), chunk_(o.chunk_), idx_(o.idx_)
{
: chunkList_(std::move(o.chunkList_)), chunk_(o.chunk_), idx_(o.idx_) {
o.chunk_ = 0;
o.idx_ = 0;
}

ChunkContainer& operator=(ChunkContainer&& o)
{
_free_memory();
chunkList_ = std::move(o.chunkList_);
chunk_ = o.chunk_;
idx_ = o.idx_;
ChunkContainer& operator=(ChunkContainer&& o) noexcept {
if (this != &o) {
_free_memory();
chunkList_ = std::move(o.chunkList_);
chunk_ = o.chunk_;
idx_ = o.idx_;
o.chunk_ = 0;
o.idx_ = 0;
}
return *this;
}

Expand Down Expand Up @@ -445,8 +449,9 @@ class ChunkContainer
{
char* chunk = reinterpret_cast<char*>(
detail::aligned_alloc(ALIGNMENT, sizeof(value_type) * chunk_size));
if (chunk == NULL)
if (chunk == nullptr) {
throw std::bad_alloc();
}
chunkList_.push_back(chunk);
}
++chunk_;
Expand Down

0 comments on commit 8597b4a

Please sign in to comment.