Coverage Report

Created: 2026-01-25 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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::non_trivial<>*
20
stack::non_trivial<>::destroy() noexcept
21
0
{
22
0
    non_trivial* const result = next;
23
0
    rel(this, nullptr);
24
0
    return result;
25
0
}
26
27
stack::non_trivial<>*
28
stack::non_trivial<>::relocate(void* dst) noexcept
29
0
{
30
0
    return rel(this, dst);
31
0
}
32
33
34
stack::
35
~stack()
36
44.9k
{
37
44.9k
    clear();
38
44.9k
    if(base_ != buf_)
39
10.5k
        sp_->deallocate(
40
10.5k
            base_, cap_);
41
44.9k
}
42
43
stack::
44
stack(
45
    storage_ptr sp,
46
    unsigned char* buf,
47
    std::size_t buf_size) noexcept
48
7.07k
    : sp_(std::move(sp))
49
7.07k
    , cap_(buf_size)
50
7.07k
    , base_(buf)
51
7.07k
    , buf_(buf)
52
7.07k
{
53
7.07k
}
54
55
void
56
stack::
57
clear() noexcept
58
87.5k
{
59
87.5k
    while(head_)
60
0
        head_ = head_->destroy();
61
87.5k
    size_ = 0;
62
87.5k
}
63
64
void
65
stack::
66
reserve_impl(std::size_t n)
67
12.2k
{
68
    // caller checks this
69
12.2k
    BOOST_ASSERT(n > cap_);
70
71
12.2k
    auto const base = static_cast<unsigned char*>( sp_->allocate(n) );
72
12.2k
    if(base_)
73
1.77k
    {
74
        // copy trivials
75
1.77k
        std::memcpy(base, base_, size_);
76
77
        // copy non-trivials
78
1.77k
        non_trivial<>* src = head_;
79
1.77k
        non_trivial<>** prev = &head_;
80
1.77k
        while(src)
81
0
        {
82
0
            std::size_t const buf_offset =
83
0
                reinterpret_cast<unsigned char*>(src) - base_;
84
0
            non_trivial<>* dest = src->relocate(base + buf_offset);
85
0
            *prev = dest;
86
0
            prev = &dest->next;
87
0
            src = dest->next;
88
0
        }
89
90
1.77k
        if(base_ != buf_)
91
1.71k
            sp_->deallocate(base_, cap_);
92
1.77k
    }
93
12.2k
    base_ = base;
94
12.2k
    cap_ = n;
95
12.2k
}
96
97
} // detail
98
} // namespace json
99
} // namespace boost
100
101
#endif