Coverage Report

Created: 2023-06-07 06:25

/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
28.1k
{
22
28.1k
    if(base_ != buf_)
23
7.24k
        sp_->deallocate(
24
7.24k
            base_, cap_);
25
28.1k
}
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.55k
{
37
4.55k
}
38
39
void
40
stack::
41
reserve(std::size_t n)
42
34.9k
{
43
34.9k
    if(cap_ >= n)
44
25.7k
        return;
45
9.10k
    auto const base = static_cast<
46
9.10k
        unsigned char*>(sp_->allocate(n));
47
9.10k
    if(base_)
48
1.91k
    {
49
1.91k
        if(size_ > 0)
50
1.91k
            std::memcpy(base, base_, size_);
51
1.91k
        if(base_ != buf_)
52
1.85k
            sp_->deallocate(base_, cap_);
53
1.91k
    }
54
9.10k
    base_ = base;
55
9.10k
    cap_ = n;
56
9.10k
}
57
58
} // detail
59
} // namespace json
60
} // namespace boost
61
62
#endif