GCC Code Coverage Report


Directory: libs/http_proto/
File: src/detail/impl/array_of_const_buffers.cpp
Date: 2025-06-18 09:40:27
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 99 array_of_const_buffers::
21 array_of_const_buffers(
22 value_type* p,
23 99 std::uint16_t n) noexcept
24 99 : base_(p)
25 99 , cap_(n)
26 99 , pos_(0)
27 99 , size_(n)
28 {
29 99 }
30
31 void
32 10863 array_of_const_buffers::
33 consume(std::size_t n)
34 {
35
2/2
✓ Branch 0 taken 10856 times.
✓ Branch 1 taken 7 times.
10863 while(size_ > 0)
36 {
37 10856 auto* p = base_ + pos_;
38
2/2
✓ Branch 1 taken 1720 times.
✓ Branch 2 taken 9136 times.
10856 if(n < p->size())
39 {
40 1720 *p = buffers::sans_prefix(*p, n);
41 1720 return;
42 }
43 9136 n -= p->size();
44 9136 ++pos_;
45 9136 --size_;
46
1/2
✓ Branch 0 taken 9136 times.
✗ Branch 1 not taken.
9136 if(n == 0)
47 9136 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 9012 array_of_const_buffers::
57 reset(std::uint16_t n) noexcept
58 {
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9012 times.
9012 BOOST_ASSERT(n <= cap_);
60 9012 pos_ = 0;
61 9012 size_ = n;
62 9012 }
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 9037 array_of_const_buffers::
78 append(value_type buf) noexcept
79 {
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9037 times.
9037 BOOST_ASSERT(size_ < cap_);
81 9037 base_[pos_ + size_] = buf;
82 9037 ++size_;
83 9037 }
84
85 } // detail
86 } // http_proto
87 } // boost
88