stack.ipp 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_DETAIL_IMPL_STACK_IPP
  10. #define BOOST_JSON_DETAIL_IMPL_STACK_IPP
  11. #include <boost/json/detail/stack.hpp>
  12. BOOST_JSON_NS_BEGIN
  13. namespace detail {
  14. stack::
  15. ~stack()
  16. {
  17. if(buf_)
  18. sp_->deallocate(
  19. buf_, cap_);
  20. }
  21. void
  22. stack::
  23. reserve(std::size_t n)
  24. {
  25. if(cap_ >= n)
  26. return;
  27. auto const buf = static_cast<
  28. char*>(sp_->allocate(n));
  29. if(buf_)
  30. {
  31. if(size_ > 0)
  32. std::memcpy(buf, buf_, size_);
  33. sp_->deallocate(buf_, cap_);
  34. }
  35. buf_ = buf;
  36. cap_ = n;
  37. }
  38. } // detail
  39. BOOST_JSON_NS_END
  40. #endif