From ba596fc83c4c8e565a32f728e6742dacb2b9d2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 11 Feb 2014 15:05:35 +0100 Subject: [PATCH] Fixes #9648, (string construction optimization) --- doc/container.qbk | 1 + include/boost/container/string.hpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/doc/container.qbk b/doc/container.qbk index 08ebbb6..302773f 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -932,6 +932,7 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs: * [@https://svn.boost.org/trac/boost/ticket/9338 #9338: ['"VS2005 compiler errors in swap() definition after including container/memory_util.hpp"]]. + * [@https://svn.boost.org/trac/boost/ticket/9648 #9648: ['"string construction optimization - char_traits::copy could be used ..."]]. [endsect] diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index 982ba4a..95187ee 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -1247,6 +1247,20 @@ class basic_string basic_string& assign(size_type n, CharT c) { return this->assign(cvalue_iterator(c, n), cvalue_iterator()); } + //! Effects: Equivalent to assign(basic_string(first, last)). + //! + //! Returns: *this + basic_string& assign(const CharT* first, const CharT* last) + { + size_type n = static_cast(last - first); + this->reserve(n); + CharT* ptr = container_detail::to_raw_pointer(this->priv_addr()); + Traits::copy(ptr, first, n); + this->priv_construct_null(ptr + n); + this->priv_size(n); + return *this; + } + //! Effects: Equivalent to assign(basic_string(first, last)). //! //! Returns: *this