GCC Code Coverage Report


Directory: libs/http_proto/
File: src/detail/impl/array_of_const_buffers.cpp
Date: 2025-06-14 21:08:33
Exec Total Coverage
Lines: 37 38 97.4%
Functions: 5 5 100.0%
Branches: 10 14 71.4%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2025 Mohammad Nejati
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/cppalliance/http_proto
9 //
10
11 #include <boost/http_proto/detail/array_of_const_buffers.hpp>
12 #include <boost/http_proto/detail/except.hpp>
13
14 #include <boost/buffers/sans_prefix.hpp>
15
16 namespace boost {
17 namespace http_proto {
18 namespace detail {
19
20 75 array_of_const_buffers::
21 array_of_const_buffers(
22 value_type* p,
23 75 std::uint16_t n) noexcept
24 75 : base_(p)
25 75 , cap_(n)
26 75 , pos_(0)
27 75 , size_(n)
28 {
29 75 }
30
31 void
32 10935 array_of_const_buffers::
33 consume(std::size_t n)
34 {
35
2/2
✓ Branch 0 taken 10928 times.
✓ Branch 1 taken 7 times.
10935 while(size_ > 0)
36 {
37 10928 auto* p = base_ + pos_;
38
2/2
✓ Branch 1 taken 1720 times.
✓ Branch 2 taken 9208 times.
10928 if(n < p->size())
39 {
40 1720 *p = buffers::sans_prefix(*p, n);
41 1720 return;
42 }
43 9208 n -= p->size();
44 9208 ++pos_;
45 9208 --size_;
46
1/2
✓ Branch 0 taken 9208 times.
✗ Branch 1 not taken.
9208 if(n == 0)
47 9208 return;
48 }
49
50 // n exceeded available size
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if(n > 0)
52 detail::throw_logic_error();
53 }
54
55 void
56 9108 array_of_const_buffers::
57 reset(std::uint16_t n) noexcept
58 {
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9108 times.
9108 BOOST_ASSERT(n <= cap_);
60 9108 pos_ = 0;
61 9108 size_ = n;
62 9108 }
63
64 void
65 2 array_of_const_buffers::
66 slide_to_front() noexcept
67 {
68 2 auto* p = base_ + pos_; // begin
69 2 auto* e = p + size_; // end
70 2 auto* d = base_; // dest
71
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 2 times.
15 while(p < e)
72 13 *d++ = *p++;
73 2 pos_ = 0;
74 2 }
75
76 void
77 9133 array_of_const_buffers::
78 append(value_type buf) noexcept
79 {
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9133 times.
9133 BOOST_ASSERT(size_ < cap_);
81 9133 base_[pos_ + size_] = buf;
82 9133 ++size_;
83 9133 }
84
85 } // detail
86 } // http_proto
87 } // boost
88