src/buffers/buffer_pair.cpp
100.0% Lines (44/44)
100.0% List of functions (2/2)
85.7% Branches (12/14)
Functions (2)
Function
Calls
Lines
Branches
Blocks
boost::capy::tag_invoke(boost::capy::slice_tag const&, std::array<boost::capy::const_buffer, 2ul>&, boost::capy::slice_how, unsigned long)
:17
0
100.0%
85.7%
–
boost::capy::tag_invoke(boost::capy::slice_tag const&, std::array<boost::capy::mutable_buffer, 2ul>&, boost::capy::slice_how, unsigned long)
:58
0
100.0%
85.7%
–
| Line | Branch | 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 | #include <boost/capy/buffers/buffer_pair.hpp> | |||
| 11 | #include <boost/capy/buffers/slice.hpp> | |||
| 12 | ||||
| 13 | namespace boost { | |||
| 14 | namespace capy { | |||
| 15 | ||||
| 16 | void | |||
| 17 | 1040x | tag_invoke( | ||
| 18 | slice_tag const&, | |||
| 19 | const_buffer_pair& bs, | |||
| 20 | slice_how how, | |||
| 21 | std::size_t n) noexcept | |||
| 22 | { | |||
| 23 |
2/3✓ Branch 0 taken 512 times.
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
|
1040x | switch(how) | |
| 24 | { | |||
| 25 | 512x | case slice_how::remove_prefix: | ||
| 26 | { | |||
| 27 | 512x | auto p = &bs[0]; | ||
| 28 |
2/2✓ Branch 1 taken 225 times.
✓ Branch 2 taken 287 times.
|
512x | if(n < p->size()) | |
| 29 | { | |||
| 30 | 225x | remove_prefix(*p, n); | ||
| 31 | 225x | return; | ||
| 32 | } | |||
| 33 | 287x | n -= p->size(); | ||
| 34 | 287x | *p = bs[1]; | ||
| 35 | 287x | bs[1] = {}; | ||
| 36 | 287x | remove_prefix(*p, n); | ||
| 37 | 287x | return; | ||
| 38 | } | |||
| 39 | ||||
| 40 | 528x | case slice_how::keep_prefix: | ||
| 41 | { | |||
| 42 | 528x | auto p = &bs[0]; | ||
| 43 |
2/2✓ Branch 1 taken 287 times.
✓ Branch 2 taken 241 times.
|
528x | if(n <= p->size()) | |
| 44 | { | |||
| 45 | 287x | keep_prefix(*p, n); | ||
| 46 | 287x | bs[1] = {}; | ||
| 47 | 287x | return; | ||
| 48 | } | |||
| 49 | 241x | n -= p->size(); | ||
| 50 | 241x | ++p; | ||
| 51 | 241x | keep_prefix(*p, n); | ||
| 52 | 241x | return; | ||
| 53 | } | |||
| 54 | } | |||
| 55 | } | |||
| 56 | ||||
| 57 | void | |||
| 58 | 1040x | tag_invoke( | ||
| 59 | slice_tag const&, | |||
| 60 | mutable_buffer_pair& bs, | |||
| 61 | slice_how how, | |||
| 62 | std::size_t n) noexcept | |||
| 63 | { | |||
| 64 |
2/3✓ Branch 0 taken 512 times.
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
|
1040x | switch(how) | |
| 65 | { | |||
| 66 | 512x | case slice_how::remove_prefix: | ||
| 67 | { | |||
| 68 | 512x | auto p = &bs[0]; | ||
| 69 |
2/2✓ Branch 1 taken 225 times.
✓ Branch 2 taken 287 times.
|
512x | if(n < p->size()) | |
| 70 | { | |||
| 71 | 225x | remove_prefix(*p, n); | ||
| 72 | 225x | return; | ||
| 73 | } | |||
| 74 | 287x | n -= p->size(); | ||
| 75 | 287x | *p = bs[1]; | ||
| 76 | 287x | bs[1] = {}; | ||
| 77 | 287x | remove_prefix(*p, n); | ||
| 78 | 287x | return; | ||
| 79 | } | |||
| 80 | ||||
| 81 | 528x | case slice_how::keep_prefix: | ||
| 82 | { | |||
| 83 | 528x | auto p = &bs[0]; | ||
| 84 |
2/2✓ Branch 1 taken 287 times.
✓ Branch 2 taken 241 times.
|
528x | if(n <= p->size()) | |
| 85 | { | |||
| 86 | 287x | keep_prefix(*p, n); | ||
| 87 | 287x | bs[1] = {}; | ||
| 88 | 287x | return; | ||
| 89 | } | |||
| 90 | 241x | n -= p->size(); | ||
| 91 | 241x | ++p; | ||
| 92 | 241x | keep_prefix(*p, n); | ||
| 93 | 241x | return; | ||
| 94 | } | |||
| 95 | } | |||
| 96 | } | |||
| 97 | ||||
| 98 | } // capy | |||
| 99 | } // boost | |||
| 100 |