76.47% Lines (26/34) 80.00% Functions (4/5)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2025 Mohammad Nejati 3   // Copyright (c) 2025 Mohammad Nejati
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 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) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/cppalliance/http 8   // Official repository: https://github.com/cppalliance/http
9   // 9   //
10   10  
11   #include "src/detail/array_of_const_buffers.hpp" 11   #include "src/detail/array_of_const_buffers.hpp"
12   12  
13   #include <boost/http/detail/except.hpp> 13   #include <boost/http/detail/except.hpp>
14   14  
15   namespace boost { 15   namespace boost {
16   namespace http { 16   namespace http {
17   namespace detail { 17   namespace detail {
18   18  
HITCBC 19   159 array_of_const_buffers:: 19   159 array_of_const_buffers::
20   array_of_const_buffers( 20   array_of_const_buffers(
21   value_type* p, 21   value_type* p,
HITCBC 22   159 std::uint16_t capacity) noexcept 22   159 std::uint16_t capacity) noexcept
HITCBC 23   159 : base_(p) 23   159 : base_(p)
HITCBC 24   159 , cap_(capacity) 24   159 , cap_(capacity)
HITCBC 25   159 , pos_(0) 25   159 , pos_(0)
HITCBC 26   159 , size_(0) 26   159 , size_(0)
27   { 27   {
HITCBC 28   159 } 28   159 }
29   29  
30   void 30   void
HITCBC 31   1985 array_of_const_buffers:: 31   1985 array_of_const_buffers::
32   consume(std::size_t n) 32   consume(std::size_t n)
33   { 33   {
HITCBC 34   2162 while(size_ > 0) 34   2162 while(size_ > 0)
35   { 35   {
HITCBC 36   1952 auto* p = base_ + pos_; 36   1952 auto* p = base_ + pos_;
HITCBC 37   1952 if(n < p->size()) 37   1952 if(n < p->size())
38   { 38   {
HITCBC 39   1775 *p += n; 39   1775 *p += n;
HITCBC 40   1775 return; 40   1775 return;
41   } 41   }
HITCBC 42   177 n -= p->size(); 42   177 n -= p->size();
HITCBC 43   177 ++pos_; 43   177 ++pos_;
HITCBC 44   177 --size_; 44   177 --size_;
45   } 45   }
46   } 46   }
47   47  
48   void 48   void
HITCBC 49   266 array_of_const_buffers:: 49   266 array_of_const_buffers::
50   reset(std::uint16_t n) noexcept 50   reset(std::uint16_t n) noexcept
51   { 51   {
HITCBC 52   266 BOOST_ASSERT(n <= cap_); 52   266 BOOST_ASSERT(n <= cap_);
HITCBC 53   266 pos_ = 0; 53   266 pos_ = 0;
HITCBC 54   266 size_ = n; 54   266 size_ = n;
HITCBC 55   266 } 55   266 }
56   56  
57   void 57   void
MISUBC 58   array_of_const_buffers:: 58   array_of_const_buffers::
59   slide_to_front() noexcept 59   slide_to_front() noexcept
60   { 60   {
MISUBC 61   auto* p = base_ + pos_; // begin 61   auto* p = base_ + pos_; // begin
MISUBC 62   auto* e = p + size_; // end 62   auto* e = p + size_; // end
MISUBC 63   auto* d = base_; // dest 63   auto* d = base_; // dest
MISUBC 64   while(p < e) 64   while(p < e)
MISUBC 65   *d++ = *p++; 65   *d++ = *p++;
MISUBC 66   pos_ = 0; 66   pos_ = 0;
MISUBC 67   } 67   }
68   68  
69   void 69   void
HITCBC 70   327 array_of_const_buffers:: 70   327 array_of_const_buffers::
71   append(value_type buf) noexcept 71   append(value_type buf) noexcept
72   { 72   {
HITCBC 73   327 BOOST_ASSERT(size_ < cap_); 73   327 BOOST_ASSERT(size_ < cap_);
HITCBC 74   327 base_[pos_ + size_] = buf; 74   327 base_[pos_ + size_] = buf;
HITCBC 75   327 ++size_; 75   327 ++size_;
HITCBC 76   327 } 76   327 }
77   77  
78   } // detail 78   } // detail
79   } // http 79   } // http
80   } // boost 80   } // boost