include/boost/capy/buffers/buffer_copy.hpp
100.0% Lines (36/36)
100.0% List of functions (14/15)
Functions (15)
Function
Calls
Lines
Blocks
<unknown function 47>
:47
–
–
–
unsigned long boost::capy::._anon_160::operator()<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>, boost::capy::mutable_buffer>(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> const&, boost::capy::mutable_buffer const&, unsigned long) const
:47
29x
100.0%
100.0%
unsigned long boost::capy::._anon_164::operator()<boost::capy::mutable_buffer, boost::capy::mutable_buffer>(boost::capy::mutable_buffer const&, boost::capy::mutable_buffer const&, unsigned long) const
:47
116x
100.0%
100.0%
unsigned long boost::capy::._anon_164::operator()<boost::capy::mutable_buffer, std::span<boost::capy::const_buffer, 18446744073709551615ul> >(boost::capy::mutable_buffer const&, std::span<boost::capy::const_buffer, 18446744073709551615ul> const&, unsigned long) const
:47
180x
100.0%
96.0%
unsigned long boost::capy::._anon_164::operator()<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>, boost::capy::mutable_buffer>(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> const&, boost::capy::mutable_buffer const&, unsigned long) const
:47
368x
100.0%
100.0%
unsigned long boost::capy::._anon_165::operator()<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>, boost::capy::mutable_buffer>(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> const&, boost::capy::mutable_buffer const&, unsigned long) const
:47
68x
100.0%
100.0%
unsigned long boost::capy::._anon_169::operator()<boost::capy::mutable_buffer, std::span<boost::capy::const_buffer const, 18446744073709551615ul> >(boost::capy::mutable_buffer const&, std::span<boost::capy::const_buffer const, 18446744073709551615ul> const&, unsigned long) const
:47
27x
100.0%
100.0%
unsigned long boost::capy::._anon_182::operator()<boost::capy::mutable_buffer, std::span<boost::capy::const_buffer const, 18446744073709551615ul> >(boost::capy::mutable_buffer const&, std::span<boost::capy::const_buffer const, 18446744073709551615ul> const&, unsigned long) const
:47
60x
100.0%
100.0%
boost::capy::._anon_160::operator()<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>, boost::capy::mutable_buffer>(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> const&, boost::capy::mutable_buffer const&, unsigned long) const::{lambda()#1}::operator()() const
:69
63x
95.0%
92.0%
boost::capy::._anon_164::operator()<boost::capy::mutable_buffer, boost::capy::mutable_buffer>(boost::capy::mutable_buffer const&, boost::capy::mutable_buffer const&, unsigned long) const::{lambda()#1}::operator()() const
:69
116x
95.0%
92.0%
boost::capy::._anon_164::operator()<boost::capy::mutable_buffer, std::span<boost::capy::const_buffer, 18446744073709551615ul> >(boost::capy::mutable_buffer const&, std::span<boost::capy::const_buffer, 18446744073709551615ul> const&, unsigned long) const::{lambda()#1}::operator()() const
:69
180x
90.0%
92.0%
boost::capy::._anon_164::operator()<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>, boost::capy::mutable_buffer>(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> const&, boost::capy::mutable_buffer const&, unsigned long) const::{lambda()#1}::operator()() const
:69
368x
95.0%
92.0%
boost::capy::._anon_165::operator()<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>, boost::capy::mutable_buffer>(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> const&, boost::capy::mutable_buffer const&, unsigned long) const::{lambda()#1}::operator()() const
:69
202x
95.0%
92.0%
boost::capy::._anon_169::operator()<boost::capy::mutable_buffer, std::span<boost::capy::const_buffer const, 18446744073709551615ul> >(boost::capy::mutable_buffer const&, std::span<boost::capy::const_buffer const, 18446744073709551615ul> const&, unsigned long) const::{lambda()#1}::operator()() const
:69
61x
95.0%
92.0%
boost::capy::._anon_182::operator()<boost::capy::mutable_buffer, std::span<boost::capy::const_buffer const, 18446744073709551615ul> >(boost::capy::mutable_buffer const&, std::span<boost::capy::const_buffer const, 18446744073709551615ul> const&, unsigned long) const::{lambda()#1}::operator()() const
:69
196x
95.0%
92.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/cppalliance/capy | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_CAPY_BUFFERS_BUFFER_COPY_HPP | ||
| 11 | #define BOOST_CAPY_BUFFERS_BUFFER_COPY_HPP | ||
| 12 | |||
| 13 | #include <boost/capy/detail/config.hpp> | ||
| 14 | #include <boost/capy/buffers.hpp> | ||
| 15 | #include <cstring> | ||
| 16 | #include <utility> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace capy { | ||
| 20 | |||
| 21 | /** Copy the contents of a buffer sequence into another buffer sequence. | ||
| 22 | |||
| 23 | @functionobject | ||
| 24 | */ | ||
| 25 | constexpr struct | ||
| 26 | { | ||
| 27 | /** Copy the contents of a buffer sequence into another buffer sequence. | ||
| 28 | |||
| 29 | Copies bytes from the constant buffer sequence `src` into the | ||
| 30 | mutable buffer sequence `dest`, stopping when any limit is | ||
| 31 | reached. | ||
| 32 | |||
| 33 | @param dest The destination buffer sequence. | ||
| 34 | |||
| 35 | @param src The source buffer sequence. | ||
| 36 | |||
| 37 | @param at_most The maximum bytes to copy. Default copies all | ||
| 38 | available. | ||
| 39 | |||
| 40 | @return The number of bytes copied, equal to | ||
| 41 | `std::min(size(dest), size(src), at_most)`. | ||
| 42 | */ | ||
| 43 | template< | ||
| 44 | MutableBufferSequence MB, | ||
| 45 | ConstBufferSequence CB> | ||
| 46 | std::size_t | ||
| 47 | 12256x | operator()( | |
| 48 | MB const& dest, | ||
| 49 | CB const& src, | ||
| 50 | std::size_t at_most = std::size_t(-1)) const noexcept | ||
| 51 | { | ||
| 52 | 12256x | std::size_t total = 0; | |
| 53 | 12256x | std::size_t pos0 = 0; | |
| 54 | 12256x | std::size_t pos1 = 0; | |
| 55 | 12256x | auto const end0 = end(src); | |
| 56 | 12256x | auto const end1 = end(dest); | |
| 57 | 12256x | auto it0 = begin(src); | |
| 58 | 12256x | auto it1 = begin(dest); | |
| 59 | 12256x | while( | |
| 60 | 38002x | total < at_most && | |
| 61 | 54380x | it0 != end0 && | |
| 62 | 9402x | it1 != end1) | |
| 63 | { | ||
| 64 | 19805x | const_buffer b0 = *it0; | |
| 65 | 19805x | mutable_buffer b1 = *it1; | |
| 66 | 19805x | b0 += pos0; | |
| 67 | 19805x | b1 += pos1; | |
| 68 | std::size_t const amount = | ||
| 69 | 59415x | [&] | |
| 70 | { | ||
| 71 | 19805x | std::size_t n = b0.size(); | |
| 72 | 19805x | if( n > b1.size()) | |
| 73 | 5750x | n = b1.size(); | |
| 74 | 19805x | if( n > at_most - total) | |
| 75 | 4902x | n = at_most - total; | |
| 76 | 19805x | if(n != 0) | |
| 77 | 18953x | std::memcpy( | |
| 78 | b1.data(), | ||
| 79 | b0.data(), | ||
| 80 | n); | ||
| 81 | 19805x | return n; | |
| 82 | 19805x | }(); | |
| 83 | 19805x | total += amount; | |
| 84 | 19805x | if(amount == b1.size()) | |
| 85 | { | ||
| 86 | 7301x | ++it1; | |
| 87 | 7301x | pos1 = 0; | |
| 88 | } | ||
| 89 | else | ||
| 90 | { | ||
| 91 | 12504x | pos1 += amount; | |
| 92 | } | ||
| 93 | 19805x | if(amount == b0.size()) | |
| 94 | { | ||
| 95 | 10569x | ++it0; | |
| 96 | 10569x | pos0 = 0; | |
| 97 | } | ||
| 98 | else | ||
| 99 | { | ||
| 100 | 9236x | pos0 += amount; | |
| 101 | } | ||
| 102 | } | ||
| 103 | 12256x | return total; | |
| 104 | } | ||
| 105 | } buffer_copy {}; | ||
| 106 | |||
| 107 | } // capy | ||
| 108 | } // boost | ||
| 109 | |||
| 110 | #endif | ||
| 111 |