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   161 array_of_const_buffers:: 19   161 array_of_const_buffers::
20   array_of_const_buffers( 20   array_of_const_buffers(
21   value_type* p, 21   value_type* p,
HITCBC 22   161 std::uint16_t capacity) noexcept 22   161 std::uint16_t capacity) noexcept
HITCBC 23   161 : base_(p) 23   161 : base_(p)
HITCBC 24   161 , cap_(capacity) 24   161 , cap_(capacity)
HITCBC 25   161 , pos_(0) 25   161 , pos_(0)
HITCBC 26   161 , size_(0) 26   161 , size_(0)
27   { 27   {
HITCBC 28   161 } 28   161 }
29   29  
30   void 30   void
HITCBC 31   1989 array_of_const_buffers:: 31   1989 array_of_const_buffers::
32   consume(std::size_t n) 32   consume(std::size_t n)
33   { 33   {
HITCBC 34   2170 while(size_ > 0) 34   2170 while(size_ > 0)
35   { 35   {
HITCBC 36   1958 auto* p = base_ + pos_; 36   1958 auto* p = base_ + pos_;
HITCBC 37   1958 if(n < p->size()) 37   1958 if(n < p->size())
38   { 38   {
HITCBC 39   1777 *p += n; 39   1777 *p += n;
HITCBC 40   1777 return; 40   1777 return;
41   } 41   }
HITCBC 42   181 n -= p->size(); 42   181 n -= p->size();
HITCBC 43   181 ++pos_; 43   181 ++pos_;
HITCBC 44   181 --size_; 44   181 --size_;
45   } 45   }
46   } 46   }
47   47  
48   void 48   void
HITCBC 49   268 array_of_const_buffers:: 49   268 array_of_const_buffers::
50   reset(std::uint16_t n) noexcept 50   reset(std::uint16_t n) noexcept
51   { 51   {
HITCBC 52   268 BOOST_ASSERT(n <= cap_); 52   268 BOOST_ASSERT(n <= cap_);
HITCBC 53   268 pos_ = 0; 53   268 pos_ = 0;
HITCBC 54   268 size_ = n; 54   268 size_ = n;
HITCBC 55   268 } 55   268 }
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   331 array_of_const_buffers:: 70   331 array_of_const_buffers::
71   append(value_type buf) noexcept 71   append(value_type buf) noexcept
72   { 72   {
HITCBC 73   331 BOOST_ASSERT(size_ < cap_); 73   331 BOOST_ASSERT(size_ < cap_);
HITCBC 74   331 base_[pos_ + size_] = buf; 74   331 base_[pos_ + size_] = buf;
HITCBC 75   331 ++size_; 75   331 ++size_;
HITCBC 76   331 } 76   331 }
77   77  
78   } // detail 78   } // detail
79   } // http 79   } // http
80   } // boost 80   } // boost