src/detail/array_of_const_buffers.cpp

76.5% Lines (26/34) 80.0% Functions (4/5)
src/detail/array_of_const_buffers.cpp
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2019 Vinnie Falco ([email protected])
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 159 array_of_const_buffers::
22 array_of_const_buffers(
23 value_type* p,
24 159 std::uint16_t capacity) noexcept
25 159 : base_(p)
26 159 , cap_(capacity)
27 159 , pos_(0)
28 159 , size_(0)
29 {
30 159 }
31
32 void
33 1985 array_of_const_buffers::
34 consume(std::size_t n)
35 {
36 2162 while(size_ > 0)
37 {
38 1952 auto* p = base_ + pos_;
39 1952 if(n < p->size())
40 {
41 1775 capy::remove_prefix(*p, n);
42 1775 return;
43 }
44 177 n -= p->size();
45 177 ++pos_;
46 177 --size_;
47 }
48 }
49
50 void
51 266 array_of_const_buffers::
52 reset(std::uint16_t n) noexcept
53 {
54 266 BOOST_ASSERT(n <= cap_);
55 266 pos_ = 0;
56 266 size_ = n;
57 266 }
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 327 array_of_const_buffers::
73 append(value_type buf) noexcept
74 {
75 327 BOOST_ASSERT(size_ < cap_);
76 327 base_[pos_ + size_] = buf;
77 327 ++size_;
78 327 }
79
80 } // detail
81 } // http
82 } // boost
83