From: Paolo Carlini Date: Mon, 5 Dec 2005 16:39:18 +0000 (+0000) Subject: sso_string_base.h (__sso_string_base<>::_M_assign): Simplify, avoid pointless realloc... X-Git-Tag: releases/gcc-4.2.0~5566 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afe6d70550d31308858263b7847731292bf06260;p=thirdparty%2Fgcc.git sso_string_base.h (__sso_string_base<>::_M_assign): Simplify, avoid pointless reallocations. 2005-12-05 Paolo Carlini * include/ext/sso_string_base.h (__sso_string_base<>::_M_assign): Simplify, avoid pointless reallocations. From-SVN: r108063 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 98ad9adf2930..12520c1bf8f4 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2005-12-05 Paolo Carlini + + * include/ext/sso_string_base.h (__sso_string_base<>::_M_assign): + Simplify, avoid pointless reallocations. + 2005-12-04 Paolo Carlini * include/ext/sso_string_base.h (__sso_string_base<>::_M_reserve): diff --git a/libstdc++-v3/include/ext/sso_string_base.h b/libstdc++-v3/include/ext/sso_string_base.h index 0a307657d462..1b967b982837 100644 --- a/libstdc++-v3/include/ext/sso_string_base.h +++ b/libstdc++-v3/include/ext/sso_string_base.h @@ -455,22 +455,22 @@ namespace __gnu_cxx { if (this != &__rcs) { - size_type __size = __rcs._M_length(); + const size_type __rsize = __rcs._M_length(); + const size_type __capacity = _M_capacity(); - _CharT* __tmp = _M_local_data; - if (__size > size_type(_S_local_capacity)) - __tmp = _M_create(__size, size_type(0)); - - _M_dispose(); - _M_data(__tmp); - - if (__size) - _S_copy(_M_data(), __rcs._M_data(), __size); + if (__rsize > __capacity) + { + size_type __new_capacity = __rsize; + _CharT* __tmp = _M_create(__new_capacity, __capacity); + _M_dispose(); + _M_data(__tmp); + _M_capacity(__new_capacity); + } - if (!_M_is_local()) - _M_capacity(__size); + if (__rsize) + _S_copy(_M_data(), __rcs._M_data(), __rsize); - _M_set_length(__size); + _M_set_length(__rsize); } }