GCC Code Coverage Report


Directory: libs/buffers/
File: libs/buffers/src/mutable_buffer_subspan.cpp
Date: 2024-07-24 21:34:17
Exec Total Coverage
Lines: 86 86 100.0%
Functions: 5 5 100.0%
Branches: 51 52 98.1%

Line Branch Exec Source
1 //
2 // Copyright (c) 2023 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/cppalliance/buffers
8 //
9
10 #include <boost/buffers/mutable_buffer_subspan.hpp>
11 #include <boost/buffers/algorithm.hpp>
12 #include <boost/assert.hpp>
13
14 namespace boost {
15 namespace buffers {
16
17 auto
18 2255 mutable_buffer_subspan::
19 const_iterator::
20 operator*() const noexcept ->
21 reference
22 {
23
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2255 times.
2255 BOOST_ASSERT(s_->n_ > 0);
24 2255 auto b = s_->p_[i_];
25
2/2
✓ Branch 0 taken 1675 times.
✓ Branch 1 taken 580 times.
2255 if(s_->n_ > 1)
26 {
27
2/2
✓ Branch 0 taken 978 times.
✓ Branch 1 taken 697 times.
1675 if(i_ > 0)
28 {
29
2/2
✓ Branch 0 taken 281 times.
✓ Branch 1 taken 697 times.
978 if(i_ < s_->n_ - 1)
30 281 return b;
31 697 return prefix(b, s_->p1_);
32 }
33 697 return sans_prefix(b, s_->p0_);
34 }
35 return { static_cast<
36 unsigned char*>(
37 580 b.data()) + s_->p0_,
38 580 s_->p1_ - s_->p0_ };
39 }
40
41 7 mutable_buffer_subspan::
42 mutable_buffer_subspan(
43 mutable_buffer const* p,
44 7 std::size_t n) noexcept
45 7 : p_(p)
46 7 , n_(n)
47 14 , p1_([&]() -> std::size_t
48 {
49
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if(n > 0)
50 6 return p[n-1].size();
51 1 return 0;
52 7 }())
53 {
54 7 }
55
56 mutable_buffer_subspan
57 732 mutable_buffer_subspan::
58 prefix_impl(
59 std::size_t n) const noexcept
60 {
61
3/3
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 146 times.
✓ Branch 2 taken 570 times.
732 switch(n_)
62 {
63 16 case 0:
64 {
65 16 return *this;
66 }
67 146 case 1:
68 {
69
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 137 times.
146 if(n == 0)
70 9 return { p_, 0, p0_, p0_ };
71
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 135 times.
137 if(n == std::size_t(-1))
72 2 return *this;
73 135 auto const d = p1_ - p0_;
74
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 77 times.
135 if(n <= d)
75 58 return { p_, 1, p0_, p0_ + n };
76 77 return *this;
77 }
78 570 default:
79 {
80
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 535 times.
570 if(n == 0)
81 35 return { p_, 0, p0_, p0_ };
82
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 525 times.
535 if(n == std::size_t(-1))
83 10 return *this;
84 525 auto d = p_[0].size() - p0_;
85
2/2
✓ Branch 0 taken 110 times.
✓ Branch 1 taken 415 times.
525 if(n <= d)
86 110 return { p_, 1, p0_, p0_ + n };
87 415 n -= d;
88 415 std::size_t i = 1;
89 for(;;)
90 {
91
2/2
✓ Branch 0 taken 275 times.
✓ Branch 1 taken 339 times.
614 if(i == n_ - 1)
92 275 break;
93
2/2
✓ Branch 1 taken 140 times.
✓ Branch 2 taken 199 times.
339 if(n <= p_[i].size())
94 140 return { p_, i + 1, p0_, n };
95 199 n -= p_[i].size();
96 199 ++i;
97 }
98
2/2
✓ Branch 0 taken 247 times.
✓ Branch 1 taken 28 times.
275 if(n <= p1_)
99 247 return { p_, n_, p0_, n };
100 28 return { p_, n_, p0_, p1_ };
101 }
102 }
103 }
104
105 mutable_buffer_subspan
106 732 mutable_buffer_subspan::
107 suffix_impl(
108 std::size_t n) const noexcept
109 {
110
3/3
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 82 times.
✓ Branch 2 taken 634 times.
732 switch(n_)
111 {
112 16 case 0:
113 {
114 16 return *this;
115 }
116 82 case 1:
117 {
118
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 77 times.
82 if(n == 0)
119 5 return { p_, 0, p1_, p1_ };
120
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 75 times.
77 if(n == std::size_t(-1))
121 2 return *this;
122 75 auto const d = p1_ - p0_;
123
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 44 times.
75 if(n < d)
124 31 return { p_, 1, p1_ - n, p1_ };
125 44 return *this;
126 }
127 634 default:
128 {
129
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 595 times.
634 if(n == 0)
130 39 return { p_, 0, p1_, p1_ };
131
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 585 times.
595 if(n == std::size_t(-1))
132 10 return *this;
133 585 std::size_t i = n_ - 1;
134
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 351 times.
585 if(n <= p1_)
135 234 return { p_ + i, 1, p1_ - n, p1_ };
136 351 n -= p1_;
137 for(;;)
138 {
139
2/2
✓ Branch 0 taken 191 times.
✓ Branch 1 taken 277 times.
468 if(--i == 0)
140 191 break;
141
2/2
✓ Branch 1 taken 160 times.
✓ Branch 2 taken 117 times.
277 if(n <= p_[i].size())
142 160 return { p_ + i, n_ - i,
143 160 p_[i].size() - n, p1_ };
144 117 n -= p_[i].size();
145 }
146 191 auto d = p_[0].size() - p0_;
147
2/2
✓ Branch 0 taken 125 times.
✓ Branch 1 taken 66 times.
191 if(n <= d)
148 125 return { p_, n_,
149 125 p_[0].size() - n, p1_ };
150 66 return { p_, n_, p0_, p1_ };
151 }
152 }
153 }
154
155 } // buffers
156 } // boost
157