libs/http/src/detail/array_of_const_buffers.cpp

76.5% Lines (26/34) 80.0% Functions (4/5) 60.0% Branches (6/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 224 array_of_const_buffers::
22 array_of_const_buffers(
23 value_type* p,
24 224 std::uint16_t capacity) noexcept
25 224 : base_(p)
26 224 , cap_(capacity)
27 224 , pos_(0)
28 224 , size_(0)
29 {
30 224 }
31
32 void
33 2124 array_of_const_buffers::
34 consume(std::size_t n)
35 {
36
2/2
✓ Branch 0 taken 2065 times.
✓ Branch 1 taken 300 times.
2365 while(size_ > 0)
37 {
38 2065 auto* p = base_ + pos_;
39
2/2
✓ Branch 1 taken 1824 times.
✓ Branch 2 taken 241 times.
2065 if(n < p->size())
40 {
41 1824 capy::remove_prefix(*p, n);
42 1824 return;
43 }
44 241 n -= p->size();
45 241 ++pos_;
46 241 --size_;
47 }
48 }
49
50 void
51 370 array_of_const_buffers::
52 reset(std::uint16_t n) noexcept
53 {
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
370 BOOST_ASSERT(n <= cap_);
55 370 pos_ = 0;
56 370 size_ = n;
57 370 }
58
59 void
60 array_of_const_buffers::
61 slide_to_front() noexcept
62 {
63 auto* p = base_ + pos_; // begin
64 auto* e = p + size_; // end
65 auto* d = base_; // dest
66 while(p < e)
67 *d++ = *p++;
68 pos_ = 0;
69 }
70
71 void
72 435 array_of_const_buffers::
73 append(value_type buf) noexcept
74 {
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 435 times.
435 BOOST_ASSERT(size_ < cap_);
76 435 base_[pos_ + size_] = buf;
77 435 ++size_;
78 435 }
79
80 } // detail
81 } // http
82 } // boost
83