Coverage Report

Created: 2023-03-26 06:57

/src/boost/boost/json/detail/impl/stack.ipp
Line
Count
Source
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
10
#ifndef BOOST_JSON_DETAIL_IMPL_STACK_IPP
11
#define BOOST_JSON_DETAIL_IMPL_STACK_IPP
12
13
#include <boost/json/detail/stack.hpp>
14
15
namespace boost {
16
namespace json {
17
namespace detail {
18
19
stack::
20
~stack()
21
27.8k
{
22
27.8k
    if(base_ != buf_)
23
7.27k
        sp_->deallocate(
24
7.27k
            base_, cap_);
25
27.8k
}
26
27
stack::
28
stack(
29
    storage_ptr sp,
30
    unsigned char* buf,
31
    std::size_t buf_size) noexcept
32
    : sp_(std::move(sp))
33
    , cap_(buf_size)
34
    , base_(buf)
35
    , buf_(buf)
36
4.52k
{
37
4.52k
}
38
39
void
40
stack::
41
reserve(std::size_t n)
42
35.5k
{
43
35.5k
    if(cap_ >= n)
44
26.4k
        return;
45
9.07k
    auto const base = static_cast<
46
9.07k
        unsigned char*>(sp_->allocate(n));
47
9.07k
    if(base_)
48
1.85k
    {
49
1.85k
        if(size_ > 0)
50
1.85k
            std::memcpy(base, base_, size_);
51
1.85k
        if(base_ != buf_)
52
1.79k
            sp_->deallocate(base_, cap_);
53
1.85k
    }
54
9.07k
    base_ = base;
55
9.07k
    cap_ = n;
56
9.07k
}
57
58
} // detail
59
} // namespace json
60
} // namespace boost
61
62
#endif