src/detail/circular_buffer.cpp
94.4% Lines (34/36)
100.0% List of functions (8/8)
78.6% Branches (11/14)
Functions (8)
Function
Calls
Lines
Branches
Blocks
boost::burl::detail::circular_buffer::empty() const
:22
252x
100.0%
–
100.0%
boost::burl::detail::circular_buffer::full() const
:29
984x
100.0%
–
100.0%
boost::burl::detail::circular_buffer::size() const
:36
1475x
100.0%
–
100.0%
boost::burl::detail::circular_buffer::data() const
:43
489x
100.0%
100.0%
100.0%
boost::burl::detail::circular_buffer::first(unsigned long) const
:53
48x
100.0%
50.0%
88.0%
boost::burl::detail::circular_buffer::prepare() const
:61
981x
100.0%
100.0%
100.0%
boost::burl::detail::circular_buffer::commit(unsigned long)
:75
974x
80.0%
50.0%
67.0%
boost::burl::detail::circular_buffer::consume(unsigned long)
:84
197x
87.5%
75.0%
80.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2026 Mohammad Nejati | |||
| 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/burl | |||
| 8 | // | |||
| 9 | ||||
| 10 | #include <boost/burl/detail/circular_buffer.hpp> | |||
| 11 | ||||
| 12 | #include "util.hpp" | |||
| 13 | ||||
| 14 | namespace boost | |||
| 15 | { | |||
| 16 | namespace burl | |||
| 17 | { | |||
| 18 | namespace detail | |||
| 19 | { | |||
| 20 | ||||
| 21 | bool | |||
| 22 | 252x | circular_buffer:: | ||
| 23 | empty() const noexcept | |||
| 24 | { | |||
| 25 | 252x | return len == 0; | ||
| 26 | } | |||
| 27 | ||||
| 28 | bool | |||
| 29 | 984x | circular_buffer:: | ||
| 30 | full() const noexcept | |||
| 31 | { | |||
| 32 | 984x | return len == cap; | ||
| 33 | } | |||
| 34 | ||||
| 35 | std::size_t | |||
| 36 | 1475x | circular_buffer:: | ||
| 37 | size() const noexcept | |||
| 38 | { | |||
| 39 | 1475x | return len; | ||
| 40 | } | |||
| 41 | ||||
| 42 | std::array<capy::const_buffer, 2> | |||
| 43 | 489x | circular_buffer:: | ||
| 44 | data() const noexcept | |||
| 45 | { | |||
| 46 |
2/2✓ Branch 0 taken 487 times.
✓ Branch 1 taken 2 times.
|
489x | if(pos + len <= cap) | |
| 47 | 487x | return { { { ptr + pos, len }, { ptr, 0 } } }; | ||
| 48 | 2x | return { { { ptr + pos, cap - pos }, | ||
| 49 | 2x | { ptr, len - (cap - pos) } } }; | ||
| 50 | } | |||
| 51 | ||||
| 52 | capy::const_buffer | |||
| 53 | 48x | circular_buffer:: | ||
| 54 | first(std::size_t n) const noexcept | |||
| 55 | { | |||
| 56 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48x | auto const k = (pos + len <= cap) ? len : cap - pos; | |
| 57 | 48x | return { ptr + pos, clamp(k, n) }; | ||
| 58 | } | |||
| 59 | ||||
| 60 | std::array<capy::mutable_buffer, 2> | |||
| 61 | 981x | circular_buffer:: | ||
| 62 | prepare() const noexcept | |||
| 63 | { | |||
| 64 | 981x | std::size_t w = pos + len; | ||
| 65 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 980 times.
|
981x | if(w >= cap) | |
| 66 | 1x | w -= cap; | ||
| 67 | 981x | std::size_t const free = cap - len; | ||
| 68 |
2/2✓ Branch 0 taken 869 times.
✓ Branch 1 taken 112 times.
|
981x | if(w + free <= cap) | |
| 69 | 869x | return { { { ptr + w, free }, { ptr, 0 } } }; | ||
| 70 | 112x | return { { { ptr + w, cap - w }, | ||
| 71 | 112x | { ptr, free - (cap - w) } } }; | ||
| 72 | } | |||
| 73 | ||||
| 74 | void | |||
| 75 | 974x | circular_buffer:: | ||
| 76 | commit(std::size_t n) noexcept | |||
| 77 | { | |||
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 974 times.
|
974x | if(n > cap - len) | |
| 79 | ✗ | n = cap - len; | ||
| 80 | 974x | len += n; | ||
| 81 | 974x | } | ||
| 82 | ||||
| 83 | void | |||
| 84 | 197x | circular_buffer:: | ||
| 85 | consume(std::size_t n) noexcept | |||
| 86 | { | |||
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 197 times.
|
197x | if(n > len) | |
| 88 | ✗ | n = len; | ||
| 89 | 197x | pos += n; | ||
| 90 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 193 times.
|
197x | if(pos >= cap) | |
| 91 | 4x | pos -= cap; | ||
| 92 | 197x | len -= n; | ||
| 93 | 197x | } | ||
| 94 | ||||
| 95 | } // namespace detail | |||
| 96 | } // namespace burl | |||
| 97 | } // namespace boost | |||
| 98 |