libs/http/src/detail/array_of_const_buffers.cpp

100.0% Lines (34/34) 100.0% Functions (5/5) 80.0% Branches (8/10)
libs/http/src/detail/array_of_const_buffers.cpp
Line Branch Hits Source Code
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
9 //
10
11 #include "src/detail/array_of_const_buffers.hpp"
12
13 #include <boost/http/detail/except.hpp>
14
15 #include <boost/capy/buffers/slice.hpp>
16
17 namespace boost {
18 namespace http {
19 namespace detail {
20
21 91 array_of_const_buffers::
22 array_of_const_buffers(
23 value_type* p,
24 91 std::uint16_t capacity) noexcept
25 91 : base_(p)
26 91 , cap_(capacity)
27 91 , pos_(0)
28 91 , size_(0)
29 {
30 91 }
31
32 void
33 1892 array_of_const_buffers::
34 consume(std::size_t n)
35 {
36
2/2
✓ Branch 0 taken 1951 times.
✓ Branch 1 taken 81 times.
2032 while(size_ > 0)
37 {
38 1951 auto* p = base_ + pos_;
39
2/2
✓ Branch 1 taken 1811 times.
✓ Branch 2 taken 140 times.
1951 if(n < p->size())
40 {
41 1811 capy::remove_prefix(*p, n);
42 1811 return;
43 }
44 140 n -= p->size();
45 140 ++pos_;
46 140 --size_;
47 }
48 }
49
50 void
51 112 array_of_const_buffers::
52 reset(std::uint16_t n) noexcept
53 {
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 BOOST_ASSERT(n <= cap_);
55 112 pos_ = 0;
56 112 size_ = n;
57 112 }
58
59 void
60 6 array_of_const_buffers::
61 slide_to_front() noexcept
62 {
63 6 auto* p = base_ + pos_; // begin
64 6 auto* e = p + size_; // end
65 6 auto* d = base_; // dest
66
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 6 times.
23 while(p < e)
67 17 *d++ = *p++;
68 6 pos_ = 0;
69 6 }
70
71 void
72 231 array_of_const_buffers::
73 append(value_type buf) noexcept
74 {
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
231 BOOST_ASSERT(size_ < cap_);
76 231 base_[pos_ + size_] = buf;
77 231 ++size_;
78 231 }
79
80 } // detail
81 } // http
82 } // boost
83