include/boost/capy/buffers/buffer_copy.hpp
100.0% Lines (36 / 36)
60.0% Functions (6 / 10, 1 excl)
Functions (11)
Function
Calls
Lines
Blocks
<unknown function 49>
:49
–
–
–
unsigned long boost::capy::._anon_122::operator()<boost::capy::detail::slice_of<boost::capy::mutable_buffer>, boost::capy::mutable_buffer>(boost::capy::detail::slice_of<boost::capy::mutable_buffer> const&, boost::capy::mutable_buffer const&, unsigned long) const
:49
0
0.0%
0.0%
unsigned long boost::capy::._anon_159::operator()<boost::capy::mutable_buffer, boost::capy::mutable_buffer>(boost::capy::mutable_buffer const&, boost::capy::mutable_buffer const&, unsigned long) const
:49
0
0.0%
0.0%
unsigned long boost::capy::._anon_161::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
:49
29x
100.0%
100.0%
unsigned long boost::capy::._anon_162::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
:49
27x
100.0%
100.0%
unsigned long boost::capy::._anon_167::operator()<boost::capy::mutable_buffer, boost::capy::mutable_buffer>(boost::capy::mutable_buffer const&, boost::capy::mutable_buffer const&, unsigned long) const
:49
170x
100.0%
91.0%
boost::capy::._anon_122::operator()<boost::capy::detail::slice_of<boost::capy::mutable_buffer>, boost::capy::mutable_buffer>(boost::capy::detail::slice_of<boost::capy::mutable_buffer> const&, boost::capy::mutable_buffer const&, unsigned long) const::{lambda()#1}::operator()() const
:71
0
0.0%
0.0%
boost::capy::._anon_159::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
:71
0
0.0%
0.0%
boost::capy::._anon_161::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
:71
63x
95.0%
92.0%
boost::capy::._anon_162::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
:71
61x
95.0%
92.0%
boost::capy::._anon_167::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
:71
170x
80.0%
83.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. The count copied is the smallest of | ||
| 32 | `buffer_size(dest)`, `buffer_size(src)`, and `at_most`. | ||
| 33 | |||
| 34 | @pre The memory regions of `dest` and `src` do not overlap. | ||
| 35 | |||
| 36 | @param dest The destination buffer sequence. | ||
| 37 | |||
| 38 | @param src The source buffer sequence. | ||
| 39 | |||
| 40 | @param at_most The maximum bytes to copy. Default copies all | ||
| 41 | available. | ||
| 42 | |||
| 43 | @return The number of bytes copied. | ||
| 44 | */ | ||
| 45 | template< | ||
| 46 | MutableBufferSequence MB, | ||
| 47 | ConstBufferSequence CB> | ||
| 48 | std::size_t | ||
| 49 | 10107x | operator()( | |
| 50 | MB const& dest, | ||
| 51 | CB const& src, | ||
| 52 | std::size_t at_most = std::size_t(-1)) const noexcept | ||
| 53 | { | ||
| 54 | 10107x | std::size_t total = 0; | |
| 55 | 10107x | std::size_t pos0 = 0; | |
| 56 | 10107x | std::size_t pos1 = 0; | |
| 57 | 10107x | auto const end0 = buffer_sequence_end(src); | |
| 58 | 10107x | auto const end1 = buffer_sequence_end(dest); | |
| 59 | 10107x | auto it0 = buffer_sequence_begin(src); | |
| 60 | 10107x | auto it1 = buffer_sequence_begin(dest); | |
| 61 | 10107x | while( | |
| 62 | 33222x | total < at_most && | |
| 63 | 47276x | it0 != end0 && | |
| 64 | 8462x | it1 != end1) | |
| 65 | { | ||
| 66 | 17393x | const_buffer b0 = *it0; | |
| 67 | 17393x | mutable_buffer b1 = *it1; | |
| 68 | 17393x | b0 += pos0; | |
| 69 | 17393x | b1 += pos1; | |
| 70 | std::size_t const amount = | ||
| 71 | 52179x | [&] | |
| 72 | { | ||
| 73 | 17393x | std::size_t n = b0.size(); | |
| 74 | 17393x | if( n > b1.size()) | |
| 75 | 5274x | n = b1.size(); | |
| 76 | 17393x | if( n > at_most - total) | |
| 77 | 4903x | n = at_most - total; | |
| 78 | 17393x | if(n != 0) | |
| 79 | 16540x | std::memcpy( | |
| 80 | b1.data(), | ||
| 81 | b0.data(), | ||
| 82 | n); | ||
| 83 | 17393x | return n; | |
| 84 | 17393x | }(); | |
| 85 | 17393x | total += amount; | |
| 86 | 17393x | if(amount == b1.size()) | |
| 87 | { | ||
| 88 | 5505x | ++it1; | |
| 89 | 5505x | pos1 = 0; | |
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | 11888x | pos1 += amount; | |
| 94 | } | ||
| 95 | 17393x | if(amount == b0.size()) | |
| 96 | { | ||
| 97 | 8632x | ++it0; | |
| 98 | 8632x | pos0 = 0; | |
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | 8761x | pos0 += amount; | |
| 103 | } | ||
| 104 | } | ||
| 105 | 10107x | return total; | |
| 106 | } | ||
| 107 | } buffer_copy {}; | ||
| 108 | |||
| 109 | } // capy | ||
| 110 | } // boost | ||
| 111 | |||
| 112 | #endif | ||
| 113 |