0.00% Lines (0/0) 0.00% Functions (0/0)
TLA Baseline Branch
Line Hits Code Line Hits 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  
DCB 20 - 1024 do_remove_prefix(  
21 - Buffer* arr,  
22 - std::size_t* count,  
23 - std::size_t* total_size,  
24 - std::size_t n) noexcept  
25 - {  
DCB 26 - 1024 if(n >= *total_size)  
27 - {  
DCB 28 - 276 while(*count > 0)  
DCB 29 - 180 arr[--(*count)].~Buffer();  
DCB 30 - 96 *total_size = 0;  
DCB 31 - 96 return;  
32 - }  
33 -  
DCB 34 - 928 std::size_t i = 0;  
DCB 35 - 1348 while(i < *count && n > 0)  
36 - {  
DCB 37 - 1260 auto& b = arr[i];  
DCB 38 - 1260 if(n < b.size())  
39 - {  
DCB 40 - 840 b += n;  
DCB 41 - 840 *total_size -= n;  
DCB 42 - 840 break;  
43 - }  
DCB 44 - 420 n -= b.size();  
DCB 45 - 420 *total_size -= b.size();  
DCB 46 - 420 b.~Buffer();  
DCB 47 - 420 ++i;  
48 - }  
49 -  
50 - // Compact: move remaining buffers to front  
DCB 51 - 928 if(i > 0)  
52 - {  
DCB 53 - 420 std::size_t j = 0;  
DCB 54 - 840 while(i < *count)  
55 - {  
DCB 56 - 420 arr[j] = arr[i];  
DCB 57 - 420 arr[i].~Buffer();  
DCB 58 - 420 ++i;  
DCB 59 - 420 ++j;  
60 - }  
DCB 61 - 420 *count = j;  
62 - }  
63 - }  
64 -  
65 - template<class Buffer>  
66 - void  
DCB 67 - 1056 do_keep_prefix(  
68 - Buffer* arr,  
69 - std::size_t* count,  
70 - std::size_t* total_size,  
71 - std::size_t n) noexcept  
72 - {  
DCB 73 - 1056 if(n >= *total_size)  
DCB 74 - 64 return;  
75 -  
DCB 76 - 992 if(n == 0)  
77 - {  
DCB 78 - 276 while(*count > 0)  
DCB 79 - 180 arr[--(*count)].~Buffer();  
DCB 80 - 96 *total_size = 0;  
DCB 81 - 96 return;  
82 - }  
83 -  
DCB 84 - 896 std::size_t remaining = n;  
DCB 85 - 896 std::size_t i = 0;  
DCB 86 - 1316 while(i < *count && remaining > 0)  
87 - {  
DCB 88 - 1260 auto& b = arr[i];  
DCB 89 - 1260 if(remaining < b.size())  
90 - {  
DCB 91 - 840 b = Buffer(b.data(), remaining);  
DCB 92 - 840 ++i;  
DCB 93 - 840 break;  
94 - }  
DCB 95 - 420 remaining -= b.size();  
DCB 96 - 420 ++i;  
97 - }  
98 -  
99 - // Destruct elements beyond the new count  
DCB 100 - 1316 while(*count > i)  
DCB 101 - 420 arr[--(*count)].~Buffer();  
102 -  
DCB 103 - 896 *total_size = n;  
104 - }  
105 -  
106 - } // anonymous namespace  
107 -  
108 - void  
DCB 109 - 512 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 - {  
DCB 115 - 512 do_remove_prefix(arr, count, total_size, n);  
DCB 116 - 512 }  
117 -  
118 - void  
DCB 119 - 512 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 - {  
DCB 125 - 512 do_remove_prefix(arr, count, total_size, n);  
DCB 126 - 512 }  
127 -  
128 - void  
DCB 129 - 528 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 - {  
DCB 135 - 528 do_keep_prefix(arr, count, total_size, n);  
DCB 136 - 528 }  
137 -  
138 - void  
DCB 139 - 528 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 - {  
DCB 145 - 528 do_keep_prefix(arr, count, total_size, n);  
DCB 146 - 528 }  
147 -  
148 - } // namespace detail  
149 - } // namespace capy  
150 - } // namespace boost