Skip to content

Commit

Permalink
refactor detail::stack::reserve_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
grisumbras committed Nov 13, 2023
1 parent b4cf85a commit 91a7303
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions include/boost/json/detail/impl/stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ struct stack::non_trivial<void>
virtual non_trivial* relocate(void*) noexcept = 0;
};

template<>
struct stack::non_trivial<void const>
: stack::non_trivial<void>
{
non_trivial* relocate(void*) noexcept { return nullptr; }

Check warning on line 36 in include/boost/json/detail/impl/stack.hpp

View check run for this annotation

Codecov / codecov/patch

include/boost/json/detail/impl/stack.hpp#L36

Added line #L36 was not covered by tests
};

template< class T >
struct stack::non_trivial
: stack::non_trivial<void>
Expand Down Expand Up @@ -63,9 +70,11 @@ reserve_impl(std::size_t n)
std::memcpy(base, base_, size_);

// copy non-trivials
non_trivial<void const> start;
start.next = nullptr;

non_trivial<>* src = head_;
non_trivial<>* prev = nullptr;
non_trivial<>* head = nullptr;
non_trivial<>* prev = &start;
while(src)
{
auto const next = src->next;
Expand All @@ -77,15 +86,11 @@ reserve_impl(std::size_t n)
dest->offset = offset;
dest->next = nullptr;

if( prev )
prev->next = dest;
else
head = dest;

prev->next = dest;
prev = dest;
src = next;
}
head_ = head;
head_ = start.next;

if(base_ != buf_)
sp_->deallocate(base_, cap_);
Expand Down

0 comments on commit 91a7303

Please sign in to comment.