src/detail/array_of_const_buffers.cpp

76.5% Lines (26/34) 80.0% List of functions (4/5)
array_of_const_buffers.cpp
f(x) Functions (5)
Line TLA 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 namespace boost {
16 namespace http {
17 namespace detail {
18
19 159x array_of_const_buffers::
20 array_of_const_buffers(
21 value_type* p,
22 159x std::uint16_t capacity) noexcept
23 159x : base_(p)
24 159x , cap_(capacity)
25 159x , pos_(0)
26 159x , size_(0)
27 {
28 159x }
29
30 void
31 1985x array_of_const_buffers::
32 consume(std::size_t n)
33 {
34 2162x while(size_ > 0)
35 {
36 1952x auto* p = base_ + pos_;
37 1952x if(n < p->size())
38 {
39 1775x *p += n;
40 1775x return;
41 }
42 177x n -= p->size();
43 177x ++pos_;
44 177x --size_;
45 }
46 }
47
48 void
49 266x array_of_const_buffers::
50 reset(std::uint16_t n) noexcept
51 {
52 266x BOOST_ASSERT(n <= cap_);
53 266x pos_ = 0;
54 266x size_ = n;
55 266x }
56
57 void
58 array_of_const_buffers::
59 slide_to_front() noexcept
60 {
61 auto* p = base_ + pos_; // begin
62 auto* e = p + size_; // end
63 auto* d = base_; // dest
64 while(p < e)
65 *d++ = *p++;
66 pos_ = 0;
67 }
68
69 void
70 327x array_of_const_buffers::
71 append(value_type buf) noexcept
72 {
73 327x BOOST_ASSERT(size_ < cap_);
74 327x base_[pos_ + size_] = buf;
75 327x ++size_;
76 327x }
77
78 } // detail
79 } // http
80 } // boost
81