LCOV - code coverage report
Current view: top level - libs/buffers/src/const_buffer_subspan.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 86 86
Test Date: 2024-07-24 21:34:17 Functions: 100.0 % 5 5

            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/buffers
       8              : //
       9              : 
      10              : #include <boost/buffers/const_buffer_subspan.hpp>
      11              : #include <boost/buffers/algorithm.hpp>
      12              : #include <boost/assert.hpp>
      13              : 
      14              : namespace boost {
      15              : namespace buffers {
      16              : 
      17              : auto
      18       772431 : const_buffer_subspan::
      19              : const_iterator::
      20              : operator*() const noexcept ->
      21              :     reference
      22              : {
      23       772431 :     BOOST_ASSERT(s_->n_ > 0);
      24       772431 :     auto b = s_->p_[i_];
      25       772431 :     if(s_->n_ > 1)
      26              :     {
      27       526091 :         if(i_ > 0)
      28              :         {
      29       246866 :             if(i_ < s_->n_ - 1)
      30          281 :                 return b;
      31       246585 :             return prefix(b, s_->p1_);
      32              :         }
      33       279225 :         return sans_prefix(b, s_->p0_);
      34              :     }
      35              :     return { static_cast<
      36              :         unsigned char const*>(
      37       246340 :             b.data()) + s_->p0_,
      38       246340 :         s_->p1_ - s_->p0_ };
      39              : }
      40              : 
      41            7 : const_buffer_subspan::
      42              : const_buffer_subspan(
      43              :     const_buffer const* p,
      44            7 :     std::size_t n) noexcept
      45            7 :     : p_(p)
      46            7 :     , n_(n)
      47           14 :     , p1_([&]() -> std::size_t
      48              :         {
      49            7 :             if(n > 0)
      50            6 :                 return p[n-1].size();
      51            1 :             return 0;
      52            7 :         }())
      53              : {
      54            7 : }
      55              : 
      56              : const_buffer_subspan
      57       139996 : const_buffer_subspan::
      58              : prefix_impl(
      59              :     std::size_t n) const noexcept
      60              : {
      61       139996 :     switch(n_)
      62              :     {
      63           16 :     case 0:
      64              :     {
      65           16 :         return *this;
      66              :     }
      67          146 :     case 1:
      68              :     {
      69          146 :         if(n == 0)
      70            9 :             return { p_, 0, p0_, p0_ };
      71          137 :         if(n == std::size_t(-1))
      72            2 :             return *this;
      73          135 :         auto const d = p1_ - p0_;
      74          135 :         if(n <= d)
      75           58 :             return { p_, 1, p0_, p0_ + n };
      76           77 :         return *this;
      77              :     }
      78       139834 :     default:
      79              :     {
      80       139834 :         if(n == 0)
      81         8227 :             return { p_, 0, p0_, p0_ };
      82       131607 :         if(n == std::size_t(-1))
      83         8202 :             return *this;
      84       123405 :         auto d = p_[0].size() - p0_;
      85       123405 :         if(n <= d)
      86        75950 :             return { p_, 1, p0_, p0_ + n };
      87        47455 :         n -= d;
      88        47455 :         std::size_t i = 1;
      89              :         for(;;)
      90              :         {
      91        47654 :             if(i == n_ - 1)
      92        47315 :                 break;
      93          339 :             if(n <= p_[i].size())
      94          140 :                 return { p_, i + 1, p0_, n };
      95          199 :             n -= p_[i].size();
      96          199 :             ++i;
      97              :         }
      98        47315 :         if(n <= p1_)
      99        47287 :             return { p_, n_, p0_, n };
     100           28 :         return { p_, n_, p0_, p1_ };
     101              :     }
     102              :     }
     103              : }
     104              : 
     105              : const_buffer_subspan
     106       139996 : const_buffer_subspan::
     107              : suffix_impl(
     108              :     std::size_t n) const noexcept
     109              : {
     110       139996 :     switch(n_)
     111              :     {
     112           16 :     case 0:
     113              :     {
     114           16 :         return *this;
     115              :     }
     116           82 :     case 1:
     117              :     {
     118           82 :         if(n == 0)
     119            5 :             return { p_, 0, p1_, p1_ };
     120           77 :         if(n == std::size_t(-1))
     121            2 :             return *this;
     122           75 :         auto const d = p1_ - p0_;
     123           75 :         if(n < d)
     124           31 :             return { p_, 1, p1_ - n, p1_ };
     125           44 :         return *this;
     126              :     }
     127       139898 :     default:
     128              :     {
     129       139898 :         if(n == 0)
     130         8231 :             return { p_, 0, p1_, p1_ };
     131       131667 :         if(n == std::size_t(-1))
     132         8202 :             return *this;
     133       123465 :         std::size_t i = n_ - 1;
     134       123465 :         if(n <= p1_)
     135        47274 :             return { p_ + i, 1, p1_ - n, p1_ };
     136        76191 :         n -= p1_;
     137              :         for(;;)
     138              :         {
     139        76308 :             if(--i == 0)
     140        76031 :                 break;
     141          277 :             if(n <= p_[i].size())
     142          160 :                 return { p_ + i, n_ - i,
     143          160 :                     p_[i].size() - n, p1_ };
     144          117 :             n -= p_[i].size();
     145              :         }
     146        76031 :         auto d = p_[0].size() - p0_;
     147        76031 :         if(n <= d)
     148        75965 :             return { p_, n_,
     149        75965 :                 p_[0].size() - n, p1_ };
     150           66 :         return { p_, n_, p0_, p1_ };
     151              :     }
     152              :     }
     153              : }
     154              : 
     155              : } // buffers
     156              : } // boost
        

Generated by: LCOV version 2.1