From 61721544f045fa45c76ac5eb5b74a58cff31530f Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 19 Jun 2019 09:26:15 -0700 Subject: [PATCH] Style tidying --- .../core/detail/impl/temporary_buffer.ipp | 42 ++++++++--------- include/boost/beast/core/detail/string.hpp | 27 ++--------- .../beast/core/detail/temporary_buffer.hpp | 12 ++--- include/boost/beast/core/impl/string.ipp | 8 ++-- include/boost/beast/core/string.hpp | 10 +---- include/boost/beast/core/string_type.hpp | 45 +++++++++++++++++++ 6 files changed, 82 insertions(+), 62 deletions(-) create mode 100644 include/boost/beast/core/string_type.hpp diff --git a/include/boost/beast/core/detail/impl/temporary_buffer.ipp b/include/boost/beast/core/detail/impl/temporary_buffer.ipp index f3dd3843..932e8473 100644 --- a/include/boost/beast/core/detail/impl/temporary_buffer.ipp +++ b/include/boost/beast/core/detail/impl/temporary_buffer.ipp @@ -13,7 +13,7 @@ #include #include #include - +#include #include #include @@ -21,44 +21,46 @@ namespace boost { namespace beast { namespace detail { - void -temporary_buffer::append(string_view sv) +temporary_buffer:: +append(string_view s) { - grow(sv.size()); - unchecked_append(sv); + grow(s.size()); + unchecked_append(s); } void -temporary_buffer::append(string_view sv1, string_view sv2) +temporary_buffer:: +append(string_view s1, string_view s2) { - grow(sv1.size() + sv2.size()); - unchecked_append(sv1); - unchecked_append(sv2); + grow(s1.size() + s2.size()); + unchecked_append(s1); + unchecked_append(s2); } void -temporary_buffer::unchecked_append(string_view sv) +temporary_buffer:: +unchecked_append(string_view s) { - auto n = sv.size(); - std::memcpy(&data_[size_], sv.data(), n); + auto n = s.size(); + std::memcpy(&data_[size_], s.data(), n); size_ += n; } void -temporary_buffer::grow(std::size_t sv_size) +temporary_buffer:: +grow(std::size_t n) { - if (capacity_ - size_ >= sv_size) - { + if (capacity_ - size_ >= n) return; - } - auto const new_cap = (sv_size + size_) * 2u; - BOOST_ASSERT(!detail::sum_exceeds(sv_size, size_, new_cap)); - char* const p = new char[new_cap]; + auto const capacity = (n + size_) * 2u; + BOOST_ASSERT(! detail::sum_exceeds( + n, size_, capacity)); + char* const p = new char[capacity]; std::memcpy(p, data_, size_); deallocate(boost::exchange(data_, p)); - capacity_ = new_cap; + capacity_ = capacity; } } // detail } // beast diff --git a/include/boost/beast/core/detail/string.hpp b/include/boost/beast/core/detail/string.hpp index 6245e127..a1b11b8b 100644 --- a/include/boost/beast/core/detail/string.hpp +++ b/include/boost/beast/core/detail/string.hpp @@ -10,35 +10,16 @@ #ifndef BOOST_BEAST_DETAIL_STRING_HPP #define BOOST_BEAST_DETAIL_STRING_HPP -#include -#include - -#if defined(BOOST_BEAST_USE_STD_STRING_VIEW) -#include -#else -#include -#endif +#include namespace boost { namespace beast { namespace detail { -#if defined(BOOST_BEAST_USE_STD_STRING_VIEW) - using string_view = std::string_view; - - template - using basic_string_view = - std::basic_string_view; -#else - using string_view = boost::string_view; - - template - using basic_string_view = - boost::basic_string_view; -#endif - -inline string_view operator "" _sv(char const* p, std::size_t n) +inline +string_view +operator"" _sv(char const* p, std::size_t n) { return string_view{p, n}; } diff --git a/include/boost/beast/core/detail/temporary_buffer.hpp b/include/boost/beast/core/detail/temporary_buffer.hpp index 2f9a16c9..8285b8f7 100644 --- a/include/boost/beast/core/detail/temporary_buffer.hpp +++ b/include/boost/beast/core/detail/temporary_buffer.hpp @@ -22,12 +22,8 @@ namespace detail { struct temporary_buffer { temporary_buffer() = default; - temporary_buffer(temporary_buffer const&) = delete; - temporary_buffer(temporary_buffer&&) = delete; - temporary_buffer& operator=(temporary_buffer const&) = delete; - temporary_buffer& operator=(temporary_buffer&&) = delete; ~temporary_buffer() noexcept { @@ -36,11 +32,11 @@ struct temporary_buffer BOOST_BEAST_DECL void - append(string_view sv); + append(string_view s); BOOST_BEAST_DECL void - append(string_view sv1, string_view sv2); + append(string_view s1, string_view s2); string_view view() const noexcept @@ -57,11 +53,11 @@ struct temporary_buffer private: BOOST_BEAST_DECL void - unchecked_append(string_view sv); + unchecked_append(string_view s); BOOST_BEAST_DECL void - grow(std::size_t sv_size); + grow(std::size_t n); void deallocate(char* data) noexcept diff --git a/include/boost/beast/core/impl/string.ipp b/include/boost/beast/core/impl/string.ipp index c3aaacdc..b64ce3f6 100644 --- a/include/boost/beast/core/impl/string.ipp +++ b/include/boost/beast/core/impl/string.ipp @@ -11,6 +11,7 @@ #define BOOST_BEAST_IMPL_STRING_IPP #include +#include #include @@ -40,7 +41,8 @@ iequals( slow: do { - if(detail::ascii_tolower(a) != detail::ascii_tolower(b)) + if( detail::ascii_tolower(a) != + detail::ascii_tolower(b)) return false; a = *p1++; b = *p2++; @@ -51,8 +53,8 @@ slow: bool iless::operator()( - string_view lhs, - string_view rhs) const + string_view lhs, + string_view rhs) const { using std::begin; using std::end; diff --git a/include/boost/beast/core/string.hpp b/include/boost/beast/core/string.hpp index 5a91ed8f..06edca19 100644 --- a/include/boost/beast/core/string.hpp +++ b/include/boost/beast/core/string.hpp @@ -10,18 +10,12 @@ #ifndef BOOST_BEAST_STRING_HPP #define BOOST_BEAST_STRING_HPP -#include +#include +#include namespace boost { namespace beast { -/// The type of string view used by the library -using detail::string_view; - -/// The type of basic string view used by the library -template -using basic_string_view = detail::basic_string_view; - /** Returns `true` if two strings are equal, using a case-insensitive comparison. The case-comparison operation is defined only for low-ASCII characters. diff --git a/include/boost/beast/core/string_type.hpp b/include/boost/beast/core/string_type.hpp new file mode 100644 index 00000000..b6b3f005 --- /dev/null +++ b/include/boost/beast/core/string_type.hpp @@ -0,0 +1,45 @@ +// +// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_STRING_TYPE_HPP +#define BOOST_BEAST_STRING_TYPE_HPP + +#include + +#if defined(BOOST_BEAST_USE_STD_STRING_VIEW) +#include +#else +#include +#endif + +namespace boost { +namespace beast { + +#if BOOST_BEAST_DOXYGEN || ! defined(BOOST_BEAST_USE_STD_STRING_VIEW) +/// The type of string view used by the library +using string_view = boost::string_view; + +/// The type of `basic_string_view` used by the library +template +using basic_string_view = + boost::basic_string_view; + +#else +using string_view = std::string_view; + +template +using basic_string_view = + std::basic_string_view; + +#endif + +} // beast +} // boost + +#endif