src/buffers/buffer_array.cpp
100.0% Lines (104/104)
100.0% List of functions (8/8)
92.9% Branches (52/56)
Functions (8)
Function
Calls
Lines
Branches
Blocks
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long)
:20
0
100.0%
92.9%
–
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long)
:20
0
100.0%
92.9%
–
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long)
:67
0
100.0%
92.9%
–
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long)
:67
0
100.0%
92.9%
–
boost::capy::detail::buffer_array_remove_prefix(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long)
:109
0
100.0%
–
–
boost::capy::detail::buffer_array_remove_prefix(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long)
:119
0
100.0%
–
–
boost::capy::detail::buffer_array_keep_prefix(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long)
:129
0
100.0%
–
–
boost::capy::detail::buffer_array_keep_prefix(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long)
:139
0
100.0%
–
–
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2025 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 | #include <boost/capy/buffers/buffer_array.hpp> | |||
| 11 | ||||
| 12 | namespace boost { | |||
| 13 | namespace capy { | |||
| 14 | namespace detail { | |||
| 15 | ||||
| 16 | namespace { | |||
| 17 | ||||
| 18 | template<class Buffer> | |||
| 19 | void | |||
| 20 | 1024x | do_remove_prefix( | ||
| 21 | Buffer* arr, | |||
| 22 | std::size_t* count, | |||
| 23 | std::size_t* total_size, | |||
| 24 | std::size_t n) noexcept | |||
| 25 | { | |||
| 26 |
4/4void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 464 times.
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 464 times.
|
1024x | if(n >= *total_size) | |
| 27 | { | |||
| 28 |
4/4void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 48 times.
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 48 times.
|
276x | while(*count > 0) | |
| 29 | 180x | arr[--(*count)].~Buffer(); | ||
| 30 | 96x | *total_size = 0; | ||
| 31 | 96x | return; | ||
| 32 | } | |||
| 33 | ||||
| 34 | 928x | std::size_t i = 0; | ||
| 35 |
6/8void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 674 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 630 times.
✓ Branch 3 taken 44 times.
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 674 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 630 times.
✓ Branch 3 taken 44 times.
|
1348x | while(i < *count && n > 0) | |
| 36 | { | |||
| 37 | 1260x | auto& b = arr[i]; | ||
| 38 |
4/4void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 1 taken 420 times.
✓ Branch 2 taken 210 times.
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 1 taken 420 times.
✓ Branch 2 taken 210 times.
|
1260x | if(n < b.size()) | |
| 39 | { | |||
| 40 | 840x | b += n; | ||
| 41 | 840x | *total_size -= n; | ||
| 42 | 840x | break; | ||
| 43 | } | |||
| 44 | 420x | n -= b.size(); | ||
| 45 | 420x | *total_size -= b.size(); | ||
| 46 | 420x | b.~Buffer(); | ||
| 47 | 420x | ++i; | ||
| 48 | } | |||
| 49 | ||||
| 50 | // Compact: move remaining buffers to front | |||
| 51 |
4/4void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 254 times.
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 254 times.
|
928x | if(i > 0) | |
| 52 | { | |||
| 53 | 420x | std::size_t j = 0; | ||
| 54 |
4/4void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 210 times.
void boost::capy::detail::(anonymous namespace)::do_remove_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 210 times.
|
840x | while(i < *count) | |
| 55 | { | |||
| 56 | 420x | arr[j] = arr[i]; | ||
| 57 | 420x | arr[i].~Buffer(); | ||
| 58 | 420x | ++i; | ||
| 59 | 420x | ++j; | ||
| 60 | } | |||
| 61 | 420x | *count = j; | ||
| 62 | } | |||
| 63 | } | |||
| 64 | ||||
| 65 | template<class Buffer> | |||
| 66 | void | |||
| 67 | 1056x | do_keep_prefix( | ||
| 68 | Buffer* arr, | |||
| 69 | std::size_t* count, | |||
| 70 | std::size_t* total_size, | |||
| 71 | std::size_t n) noexcept | |||
| 72 | { | |||
| 73 |
4/4void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 496 times.
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 496 times.
|
1056x | if(n >= *total_size) | |
| 74 | 64x | return; | ||
| 75 | ||||
| 76 |
4/4void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 448 times.
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 448 times.
|
992x | if(n == 0) | |
| 77 | { | |||
| 78 |
4/4void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 48 times.
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 48 times.
|
276x | while(*count > 0) | |
| 79 | 180x | arr[--(*count)].~Buffer(); | ||
| 80 | 96x | *total_size = 0; | ||
| 81 | 96x | return; | ||
| 82 | } | |||
| 83 | ||||
| 84 | 896x | std::size_t remaining = n; | ||
| 85 | 896x | std::size_t i = 0; | ||
| 86 |
6/8void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 630 times.
✓ Branch 3 taken 28 times.
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 630 times.
✓ Branch 3 taken 28 times.
|
1316x | while(i < *count && remaining > 0) | |
| 87 | { | |||
| 88 | 1260x | auto& b = arr[i]; | ||
| 89 |
4/4void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 1 taken 420 times.
✓ Branch 2 taken 210 times.
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 1 taken 420 times.
✓ Branch 2 taken 210 times.
|
1260x | if(remaining < b.size()) | |
| 90 | { | |||
| 91 | 840x | b = Buffer(b.data(), remaining); | ||
| 92 | 840x | ++i; | ||
| 93 | 840x | break; | ||
| 94 | } | |||
| 95 | 420x | remaining -= b.size(); | ||
| 96 | 420x | ++i; | ||
| 97 | } | |||
| 98 | ||||
| 99 | // Destruct elements beyond the new count | |||
| 100 |
4/4void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::const_buffer>(boost::capy::const_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 448 times.
void boost::capy::detail::(anonymous namespace)::do_keep_prefix<boost::capy::mutable_buffer>(boost::capy::mutable_buffer*, unsigned long*, unsigned long*, unsigned long):
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 448 times.
|
1316x | while(*count > i) | |
| 101 | 420x | arr[--(*count)].~Buffer(); | ||
| 102 | ||||
| 103 | 896x | *total_size = n; | ||
| 104 | } | |||
| 105 | ||||
| 106 | } // anonymous namespace | |||
| 107 | ||||
| 108 | void | |||
| 109 | 512x | buffer_array_remove_prefix( | ||
| 110 | const_buffer* arr, | |||
| 111 | std::size_t* count, | |||
| 112 | std::size_t* total_size, | |||
| 113 | std::size_t n) noexcept | |||
| 114 | { | |||
| 115 | 512x | do_remove_prefix(arr, count, total_size, n); | ||
| 116 | 512x | } | ||
| 117 | ||||
| 118 | void | |||
| 119 | 512x | buffer_array_remove_prefix( | ||
| 120 | mutable_buffer* arr, | |||
| 121 | std::size_t* count, | |||
| 122 | std::size_t* total_size, | |||
| 123 | std::size_t n) noexcept | |||
| 124 | { | |||
| 125 | 512x | do_remove_prefix(arr, count, total_size, n); | ||
| 126 | 512x | } | ||
| 127 | ||||
| 128 | void | |||
| 129 | 528x | buffer_array_keep_prefix( | ||
| 130 | const_buffer* arr, | |||
| 131 | std::size_t* count, | |||
| 132 | std::size_t* total_size, | |||
| 133 | std::size_t n) noexcept | |||
| 134 | { | |||
| 135 | 528x | do_keep_prefix(arr, count, total_size, n); | ||
| 136 | 528x | } | ||
| 137 | ||||
| 138 | void | |||
| 139 | 528x | buffer_array_keep_prefix( | ||
| 140 | mutable_buffer* arr, | |||
| 141 | std::size_t* count, | |||
| 142 | std::size_t* total_size, | |||
| 143 | std::size_t n) noexcept | |||
| 144 | { | |||
| 145 | 528x | do_keep_prefix(arr, count, total_size, n); | ||
| 146 | 528x | } | ||
| 147 | ||||
| 148 | } // namespace detail | |||
| 149 | } // namespace capy | |||
| 150 | } // namespace boost | |||
| 151 |