]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/detail/impl/temporary_buffer.ipp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / beast / core / detail / impl / temporary_buffer.ipp
1 //
2 // Copyright (c) 2019 Damian Jarek(damian.jarek93@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/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_DETAIL_IMPL_TEMPORARY_BUFFER_IPP
11 #define BOOST_BEAST_DETAIL_IMPL_TEMPORARY_BUFFER_IPP
12
13 #include <boost/beast/core/detail/temporary_buffer.hpp>
14 #include <boost/beast/core/detail/clamp.hpp>
15 #include <boost/core/exchange.hpp>
16 #include <boost/assert.hpp>
17 #include <memory>
18 #include <cstring>
19
20 namespace boost {
21 namespace beast {
22 namespace detail {
23
24 void
25 temporary_buffer::
26 append(string_view s)
27 {
28 grow(s.size());
29 unchecked_append(s);
30 }
31
32 void
33 temporary_buffer::
34 append(string_view s1, string_view s2)
35 {
36 grow(s1.size() + s2.size());
37 unchecked_append(s1);
38 unchecked_append(s2);
39 }
40
41 void
42 temporary_buffer::
43 unchecked_append(string_view s)
44 {
45 auto n = s.size();
46 std::memcpy(&data_[size_], s.data(), n);
47 size_ += n;
48 }
49
50 void
51 temporary_buffer::
52 grow(std::size_t n)
53 {
54 if (capacity_ - size_ >= n)
55 return;
56
57 auto const capacity = (n + size_) * 2u;
58 BOOST_ASSERT(! detail::sum_exceeds(
59 n, size_, capacity));
60 char* const p = new char[capacity];
61 std::memcpy(p, data_, size_);
62 deallocate(boost::exchange(data_, p));
63 capacity_ = capacity;
64 }
65 } // detail
66 } // beast
67 } // boost
68
69 #endif