LCOV - code coverage report
Current view: top level - /jenkins/workspace/boost-root/libs/capy/src/buffers - circular_dynamic_buffer.cpp (source / functions) Coverage Total Hit Missed
Test: coverage_remapped.info Lines: 75.8 % 33 25 8
Test Date: 2026-02-17 18:14:47 Functions: 100.0 % 4 4

           TLA  Line data    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/circular_dynamic_buffer.hpp>
      11                 : #include <boost/capy/detail/except.hpp>
      12                 : 
      13                 : namespace boost {
      14                 : namespace capy {
      15                 : 
      16                 : auto
      17 HIT         166 : circular_dynamic_buffer::
      18                 : data() const noexcept ->
      19                 :     const_buffers_type
      20                 : {
      21             166 :     if(in_pos_ + in_len_ <= cap_)
      22                 :         return {{
      23             166 :             const_buffer{ base_ + in_pos_, in_len_ },
      24             166 :             const_buffer{ base_, 0} }};
      25                 :     return {{
      26 MIS           0 :         const_buffer{ base_ + in_pos_, cap_ - in_pos_},
      27               0 :         const_buffer{ base_, in_len_- (cap_ - in_pos_)} }};
      28                 : }
      29                 : 
      30                 : auto
      31 HIT         230 : circular_dynamic_buffer::
      32                 : prepare(std::size_t n) ->
      33                 :     mutable_buffers_type
      34                 : {
      35                 :     // Buffer is too small for n
      36             230 :     if(n > cap_ - in_len_)
      37               1 :         detail::throw_length_error();
      38                 : 
      39             229 :     out_size_ = n;
      40             229 :     auto const pos = (
      41             229 :         in_pos_ + in_len_) % cap_;
      42             229 :     if(pos + n <= cap_)
      43                 :         return {{
      44             229 :             mutable_buffer{ base_ + pos, n },
      45             229 :             mutable_buffer{ base_, 0 } }};
      46                 :     return {{
      47 MIS           0 :         mutable_buffer{ base_ + pos, cap_ - pos },
      48               0 :         mutable_buffer{ base_, n - (cap_ - pos) } }};
      49                 : }
      50                 : 
      51                 : void
      52 HIT         192 : circular_dynamic_buffer::
      53                 : commit(
      54                 :     std::size_t n) noexcept
      55                 : {
      56             192 :     if(n < out_size_)
      57              48 :         in_len_ += n;
      58                 :     else
      59             144 :         in_len_ += out_size_;
      60             192 :     out_size_ = 0;
      61             192 : }
      62                 : 
      63                 : void
      64             164 : circular_dynamic_buffer::
      65                 : consume(
      66                 :     std::size_t n) noexcept
      67                 : {
      68             164 :     if(n < in_len_)
      69                 :     {
      70 MIS           0 :         in_pos_ = (in_pos_ + n) % cap_;
      71               0 :         in_len_ -= n;
      72                 :     }
      73                 :     else
      74                 :     {
      75                 :         // preserve in_pos_ if there is
      76                 :         // a prepared buffer
      77 HIT         164 :         if(out_size_ != 0)
      78                 :         {
      79 MIS           0 :             in_pos_ = (in_pos_ + in_len_) % cap_;
      80               0 :             in_len_ = 0;
      81                 :         }
      82                 :         else
      83                 :         {
      84                 :             // make prepare return a
      85                 :             // bigger single buffer
      86 HIT         164 :             in_pos_ = 0;
      87             164 :             in_len_ = 0;
      88                 :         }
      89                 :     }
      90             164 : }
      91                 : 
      92                 : } // capy
      93                 : } // boost
        

Generated by: LCOV version 2.3