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