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/buffer_pair.hpp>
11 : #include <boost/buffers/slice.hpp>
12 :
13 : namespace boost {
14 : namespace buffers {
15 :
16 : void
17 6529856 : tag_invoke(
18 : slice_tag const&,
19 : const_buffer_pair& bs,
20 : slice_how how,
21 : std::size_t n) noexcept
22 : {
23 6529856 : switch(how)
24 : {
25 2993536 : case slice_how::remove_prefix:
26 : {
27 2993536 : auto p = &bs[0];
28 2993536 : if(n < p->size())
29 : {
30 1834873 : remove_prefix(*p, n);
31 1834873 : return;
32 : }
33 1158663 : n -= p->size();
34 1158663 : *p = bs[1];
35 1158663 : bs[1] = {};
36 1158663 : remove_prefix(*p, n);
37 1158663 : return;
38 : }
39 :
40 3536320 : case slice_how::keep_prefix:
41 : {
42 3536320 : auto p = &bs[0];
43 3536320 : if(n <= p->size())
44 : {
45 2718075 : keep_prefix(*p, n);
46 2718075 : bs[1] = {};
47 2718075 : return;
48 : }
49 818245 : n -= p->size();
50 818245 : ++p;
51 818245 : keep_prefix(*p, n);
52 818245 : return;
53 : }
54 : }
55 : }
56 :
57 : void
58 25408 : tag_invoke(
59 : slice_tag const&,
60 : mutable_buffer_pair& bs,
61 : slice_how how,
62 : std::size_t n) noexcept
63 : {
64 25408 : switch(how)
65 : {
66 11648 : case slice_how::remove_prefix:
67 : {
68 11648 : auto p = &bs[0];
69 11648 : if(n < p->size())
70 : {
71 6425 : remove_prefix(*p, n);
72 6425 : return;
73 : }
74 5223 : n -= p->size();
75 5223 : *p = bs[1];
76 5223 : bs[1] = {};
77 5223 : remove_prefix(*p, n);
78 5223 : return;
79 : }
80 :
81 13760 : case slice_how::keep_prefix:
82 : {
83 13760 : auto p = &bs[0];
84 13760 : if(n <= p->size())
85 : {
86 9883 : keep_prefix(*p, n);
87 9883 : bs[1] = {};
88 9883 : return;
89 : }
90 3877 : n -= p->size();
91 3877 : ++p;
92 3877 : keep_prefix(*p, n);
93 3877 : return;
94 : }
95 : }
96 : }
97 :
98 : } // buffers
99 : } // boost
|