| Line | Branch | Exec | Source |
|---|---|---|---|
| 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/buffers | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_BUFFERS_COPY_HPP | ||
| 11 | #define BOOST_BUFFERS_COPY_HPP | ||
| 12 | |||
| 13 | #include <boost/buffers/detail/config.hpp> | ||
| 14 | #include <boost/buffers/buffer.hpp> | ||
| 15 | #include <cstring> | ||
| 16 | #include <utility> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace buffers { | ||
| 20 | |||
| 21 | /** Copy the contents of a buffer sequence into another buffer sequence | ||
| 22 | |||
| 23 | This function copies no more than `at_most` bytes from the constant buffer | ||
| 24 | sequence denoted by `src` into the mutable buffer sequence denoted by `dest`. | ||
| 25 | |||
| 26 | @par Constraints | ||
| 27 | @code | ||
| 28 | requires is_mutable_buffer_sequence_v<decltype(dest)> && | ||
| 29 | is_const_buffer_sequence_v<decltype(src)>; | ||
| 30 | @endcode | ||
| 31 | |||
| 32 | @return The number of bytes actually copied, which will be exactly equal to | ||
| 33 | `std::min( size(dest), size(src), at_most )`. | ||
| 34 | |||
| 35 | @param dest The destination buffer sequence | ||
| 36 | |||
| 37 | @param src The source buffer sequence | ||
| 38 | */ | ||
| 39 | constexpr struct copy_mrdocs_workaround_t | ||
| 40 | { | ||
| 41 | template< | ||
| 42 | class MutableBufferSequence, | ||
| 43 | class ConstBufferSequence> | ||
| 44 | auto | ||
| 45 | 599514 | operator()( | |
| 46 | MutableBufferSequence const& dest, | ||
| 47 | ConstBufferSequence const& src, | ||
| 48 | std::size_t at_most = std::size_t(-1)) const noexcept -> typename std::enable_if< | ||
| 49 | is_mutable_buffer_sequence<MutableBufferSequence>::value && | ||
| 50 | is_const_buffer_sequence<ConstBufferSequence>::value, std::size_t>::type | ||
| 51 | { | ||
| 52 | 599514 | std::size_t total = 0; | |
| 53 | 599514 | std::size_t pos0 = 0; | |
| 54 | 599514 | std::size_t pos1 = 0; | |
| 55 | 599514 | auto const end0 = end(src); | |
| 56 | 599514 | auto const end1 = end(dest); | |
| 57 | 599514 | auto it0 = begin(src); | |
| 58 | 599514 | auto it1 = begin(dest); | |
| 59 | 599514 | while( | |
| 60 |
2/2✓ Branch 0 taken 658 times.
✓ Branch 1 taken 175 times.
|
1617646 | total < at_most && |
| 61 |
6/7✓ Branch 0 taken 833 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 424 times.
✓ Branch 3 taken 234 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 168 times.
✓ Branch 6 taken 88 times.
|
2935171 | it0 != end0 && |
| 62 | 2 | it1 != end1) | |
| 63 | { | ||
| 64 | 1024594 | const_buffer b0 = *it0; | |
| 65 | 1024594 | mutable_buffer b1 = *it1; | |
| 66 | 1024594 | b0 += pos0; | |
| 67 | 1024594 | b1 += pos1; | |
| 68 | std::size_t const amount = | ||
| 69 | 3073782 | [&] | |
| 70 | { | ||
| 71 | 1024594 | std::size_t n = b0.size(); | |
| 72 |
15/24✓ Branch 1 taken 338 times.
✓ Branch 2 taken 965168 times.
✓ Branch 4 taken 12281 times.
✓ Branch 5 taken 28319 times.
✓ Branch 7 taken 11034 times.
✓ Branch 8 taken 7423 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 3 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 2 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 2 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 11 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
|
1024594 | if( n > b1.size()) |
| 73 | 23653 | n = b1.size(); | |
| 74 |
14/24✗ Branch 0 not taken.
✓ Branch 1 taken 965506 times.
✓ Branch 2 taken 3150 times.
✓ Branch 3 taken 37450 times.
✓ Branch 4 taken 1728 times.
✓ Branch 5 taken 16729 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 11 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
|
1024594 | if( n > at_most - total) |
| 75 | 4878 | n = at_most - total; | |
| 76 |
15/24✓ Branch 0 taken 723556 times.
✓ Branch 1 taken 241950 times.
✓ Branch 2 taken 32617 times.
✓ Branch 3 taken 7983 times.
✓ Branch 4 taken 15211 times.
✓ Branch 5 taken 3246 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 11 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1024594 | if(n != 0) |
| 77 | 771415 | std::memcpy( | |
| 78 | b1.data(), | ||
| 79 | b0.data(), | ||
| 80 | n); | ||
| 81 | 1024594 | return n; | |
| 82 | 1024594 | }(); | |
| 83 | 1024594 | total += amount; | |
| 84 |
2/2✓ Branch 1 taken 373 times.
✓ Branch 2 taken 217 times.
|
1024594 | if(amount == b1.size()) |
| 85 | { | ||
| 86 | 32093 | ++it1; | |
| 87 | 32093 | pos1 = 0; | |
| 88 | } | ||
| 89 | else | ||
| 90 | { | ||
| 91 | 992501 | pos1 += amount; | |
| 92 | } | ||
| 93 |
2/2✓ Branch 1 taken 253 times.
✓ Branch 2 taken 337 times.
|
1024594 | if(amount == b0.size()) |
| 94 | { | ||
| 95 | 997479 | ++it0; | |
| 96 | 997479 | pos0 = 0; | |
| 97 | } | ||
| 98 | else | ||
| 99 | { | ||
| 100 | 27115 | pos0 += amount; | |
| 101 | } | ||
| 102 | } | ||
| 103 | 599516 | return total; | |
| 104 | 2 | } | |
| 105 | } copy {}; | ||
| 106 | |||
| 107 | } // buffers | ||
| 108 | } // boost | ||
| 109 | |||
| 110 | #endif | ||
| 111 |