From 97a7e83368090c40747c7ee9473a3e338ba0c7f3 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 21 Feb 2020 19:21:48 -0500 Subject: [PATCH] Add unchecked assignment --- include/boost/static_string/static_string.hpp | 59 +++++++++++++------ 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index 4b4b0f7..b440c2e 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -940,36 +940,40 @@ public: Replace the contents with a copy of another `basic_static_string` + @throw std::length_error if `s.size() > max_size()` @return `*this` */ + template::type* = nullptr +#endif + > + BOOST_STATIC_STRING_CPP14_CONSTEXPR + basic_static_string& + assign(const basic_static_string& s) + { + return assign_unchecked(s.data(), s.size()); + } + +#ifndef GENERATING_DOCUMENTATION BOOST_STATIC_STRING_CPP14_CONSTEXPR basic_static_string& assign(const basic_static_string& s) noexcept { if (this == &s) return *this; - this->set_size(s.size()); - traits_type::copy(data(), &s.data()[0], size() + 1); - return *this; + return assign_unchecked(s.data(), s.size()); } - /** Replace the contents. - - Replace the contents with a copy of another `basic_static_string` - - @throw std::length_error if `s.size() > max_size()` - @return `*this` - */ - template + template N)>::type* = nullptr> BOOST_STATIC_STRING_CPP14_CONSTEXPR basic_static_string& assign(const basic_static_string& s) { - // VFALCO this could come in two flavors, - // N > M and N < M, and skip the exception - // check when N > M return assign(s.data(), s.size()); } +#endif /** Replace the contents. @@ -4103,6 +4107,12 @@ private: const_pointer s, size_type count); + BOOST_STATIC_STRING_CPP14_CONSTEXPR + basic_static_string& + assign_unchecked( + const_pointer s, + size_type count) noexcept; + BOOST_STATIC_STRING_CPP14_CONSTEXPR size_type capped_length( @@ -4987,9 +4997,9 @@ basic_static_string:: copy(pointer dest, size_type count, size_type pos) const -> size_type { - const auto s = subview(pos, count); - traits_type::copy(dest, s.data(), s.size()); - return s.size(); + const auto num_copied = capped_length(pos, count); + traits_type::copy(dest, data() + pos, num_copied); + return num_copied; } template @@ -5372,6 +5382,21 @@ insert_unchecked( this->set_size(curr_size + count); return curr_data + index; } + +template +BOOST_STATIC_STRING_CPP14_CONSTEXPR +auto +basic_static_string:: +assign_unchecked( + const_pointer s, + size_type count) noexcept -> + basic_static_string& +{ + this->set_size(count); + traits_type::copy(data(), s, size() + 1); + return *this; +} + } // static_string } // boost #endif