Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:03:42

0001 //
0002 // Copyright (c) 2019 Damian Jarek(damian.jarek93@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_DETAIL_IMPL_TEMPORARY_BUFFER_IPP
0011 #define BOOST_BEAST_DETAIL_IMPL_TEMPORARY_BUFFER_IPP
0012 
0013 #include <boost/beast/core/detail/temporary_buffer.hpp>
0014 #include <boost/beast/core/detail/clamp.hpp>
0015 #include <boost/core/exchange.hpp>
0016 #include <boost/assert.hpp>
0017 #include <memory>
0018 #include <cstring>
0019 
0020 namespace boost {
0021 namespace beast {
0022 namespace detail {
0023 
0024 void
0025 temporary_buffer::
0026 append(string_view s)
0027 {
0028     grow(s.size());
0029     unchecked_append(s);
0030 }
0031 
0032 void
0033 temporary_buffer::
0034 append(string_view s1, string_view s2)
0035 {
0036     grow(s1.size() + s2.size());
0037     unchecked_append(s1);
0038     unchecked_append(s2);
0039 }
0040 
0041 void
0042 temporary_buffer::
0043 unchecked_append(string_view s)
0044 {
0045     auto n = s.size();
0046     std::memcpy(&data_[size_], s.data(), n);
0047     size_ += n;
0048 }
0049 
0050 void
0051 temporary_buffer::
0052 grow(std::size_t n)
0053 {
0054     if (capacity_ - size_ >= n)
0055         return;
0056 
0057     auto const capacity = (n + size_) * 2u;
0058     BOOST_ASSERT(! detail::sum_exceeds(
0059         n, size_, capacity));
0060     char* const p = new char[capacity];
0061     std::memcpy(p, data_, size_);
0062     deallocate(boost::exchange(data_, p));
0063     capacity_ = capacity;
0064 }
0065 } // detail
0066 } // beast
0067 } // boost
0068 
0069 #endif