This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] Further tweak sso_string::_M_swap
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 03 Nov 2005 14:11:42 +0100
- Subject: [v3] Further tweak sso_string::_M_swap
Hi,
I'm happy to report that with this tweak, on testcases like
moveable_vector_insert.cc, thanks to move semantics on the v7-branch we
are typically 2 times faster than our "old" reference-counted
implementation, both for short and long strings.
Tested x86-linux, both mainline and v7-branch (which uses sso_string by
default)
Paolo.
///////////////////
2005-11-03 Paolo Carlini <pcarlini@suse.de>
* include/ext/sso_string_base.h (__sso_string_base<>::_M_swap):
Change the various traits_type::copy call to always copy the
entire local buffer; return early and don't do a full swap on
the lengths for two common cases; change two _S_copy to plain
traits_type::copy.
Index: include/ext/sso_string_base.h
===================================================================
--- include/ext/sso_string_base.h (revision 106378)
+++ include/ext/sso_string_base.h (working copy)
@@ -255,29 +255,34 @@
{
_CharT __tmp_data[_S_local_capacity + 1];
traits_type::copy(__tmp_data, __rcs._M_local_data,
- __rcs._M_length() + 1);
+ _S_local_capacity + 1);
traits_type::copy(__rcs._M_local_data, _M_local_data,
- _M_length() + 1);
+ _S_local_capacity + 1);
traits_type::copy(_M_local_data, __tmp_data,
- __rcs._M_length() + 1);
+ _S_local_capacity + 1);
}
else if (__rcs._M_length())
{
traits_type::copy(_M_local_data, __rcs._M_local_data,
- __rcs._M_length() + 1);
- traits_type::assign(__rcs._M_local_data[0], _CharT());
+ _S_local_capacity + 1);
+ _M_length(__rcs._M_length());
+ __rcs._M_set_length(0);
+ return;
}
else if (_M_length())
{
traits_type::copy(__rcs._M_local_data, _M_local_data,
- _M_length() + 1);
- traits_type::assign(_M_local_data[0], _CharT());
+ _S_local_capacity + 1);
+ __rcs._M_length(_M_length());
+ _M_set_length(0);
+ return;
}
}
else
{
const size_type __tmp_capacity = __rcs._M_allocated_capacity;
- _S_copy(__rcs._M_local_data, _M_local_data, _M_length() + 1);
+ traits_type::copy(__rcs._M_local_data, _M_local_data,
+ _S_local_capacity + 1);
_M_data(__rcs._M_data());
__rcs._M_data(__rcs._M_local_data);
_M_capacity(__tmp_capacity);
@@ -287,8 +292,8 @@
const size_type __tmp_capacity = _M_allocated_capacity;
if (__rcs._M_is_local())
{
- _S_copy(_M_local_data, __rcs._M_local_data,
- __rcs._M_length() + 1);
+ traits_type::copy(_M_local_data, __rcs._M_local_data,
+ _S_local_capacity + 1);
__rcs._M_data(_M_data());
_M_data(_M_local_data);
}