From afe6d70550d31308858263b7847731292bf06260 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 5 Dec 2005 16:39:18 +0000 Subject: [PATCH] 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 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/include/ext/sso_string_base.h | 26 +++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 98ad9adf293..12520c1bf8f 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 0a307657d46..1b967b98283 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)); + if (__rsize > __capacity) + { + size_type __new_capacity = __rsize; + _CharT* __tmp = _M_create(__new_capacity, __capacity); + _M_dispose(); + _M_data(__tmp); + _M_capacity(__new_capacity); + } - _M_dispose(); - _M_data(__tmp); + if (__rsize) + _S_copy(_M_data(), __rcs._M_data(), __rsize); - if (__size) - _S_copy(_M_data(), __rcs._M_data(), __size); - - if (!_M_is_local()) - _M_capacity(__size); - - _M_set_length(__size); + _M_set_length(__rsize); } }