This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Batch of basic_string correctness and performance work
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Paolo Carlini <pcarlini at suse dot de>
- Cc: Gawain Bolton <gp dot bolton at computer dot org>,libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 25 Oct 2004 23:39:53 +0200
- Subject: Re: [Patch] Batch of basic_string correctness and performance work
- References: <417BE78A.2050307@suse.de> <417D5FBE.7010305@computer.org> <417D690E.3060501@suse.de>
Paolo Carlini wrote:
That said, all those append (and operator+=), in the present form
perform much better anyway, also if not-inlined (see, f.i.,
append(const _CharT*, size_type) or, better example, append(const
basic_string&, size_type, size_type), which I purposedly kept
off-line), therefore, please provide a little bit of evidence that one
of your applications would take advantage from moving the functions
out of line and I will happily do that!
To give you an idea, this is what happen performance-wise on the ubenchmarks
if I move out of line both append(size_type __n, _CharT __c) (append(char)
actually means append(1, c)) and append(const basic_string&), at issue (I
think push_back and operator+=(_CharT) are not seriously in discussion):
current
-------
Execution time of 10000000 string::append(char) calls: 0.14 sec.
Execution time of 10000000 string::append(const string&) calls: 0.14 sec.
current + out of line
---------------------
Execution time of 10000000 string::append(char) calls: 0.24 sec.
Execution time of 10000000 string::append(const string&) calls: 0.23 sec.
old
---
Execution time of 10000000 string::append(char) calls: 0.26 sec.
Execution time of 10000000 string::append(const string&) calls: 0.49 sec.
Please, test a bit the attached and provide some feedback at your ease,
we have still a good amount of time before 4.0.0...
Paolo.
//////////////
diff -urN libstdc++-v3-orig/include/bits/basic_string.h libstdc++-v3/include/bits/basic_string.h
--- libstdc++-v3-orig/include/bits/basic_string.h 2004-10-24 10:35:29.000000000 +0200
+++ libstdc++-v3/include/bits/basic_string.h 2004-10-25 23:23:09.000000000 +0200
@@ -776,19 +776,7 @@
* @return Reference to this string.
*/
basic_string&
- append(const basic_string& __str)
- {
- const size_type __size = __str.size();
- if (__size)
- {
- const size_type __len = __size + this->size();
- if (__len > this->capacity() || _M_rep()->_M_is_shared())
- this->reserve(__len);
- _M_copy(_M_data() + this->size(), __str._M_data(), __size);
- _M_rep()->_M_set_length_and_sharable(__len);
- }
- return *this;
- }
+ append(const basic_string& __str);
/**
* @brief Append a substring.
@@ -835,19 +823,7 @@
* Appends n copies of c to this string.
*/
basic_string&
- append(size_type __n, _CharT __c)
- {
- if (__n)
- {
- _M_check_length(size_type(0), __n, "basic_string::append");
- const size_type __len = __n + this->size();
- if (__len > this->capacity() || _M_rep()->_M_is_shared())
- this->reserve(__len);
- _M_assign(_M_data() + this->size(), __n, __c);
- _M_rep()->_M_set_length_and_sharable(__len);
- }
- return *this;
- }
+ append(size_type __n, _CharT __c);
/**
* @brief Append a range of characters.
diff -urN libstdc++-v3-orig/include/bits/basic_string.tcc libstdc++-v3/include/bits/basic_string.tcc
--- libstdc++-v3-orig/include/bits/basic_string.tcc 2004-10-25 12:36:56.000000000 +0200
+++ libstdc++-v3/include/bits/basic_string.tcc 2004-10-25 23:22:57.000000000 +0200
@@ -264,6 +264,40 @@
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>&
basic_string<_CharT, _Traits, _Alloc>::
+ append(size_type __n, _CharT __c)
+ {
+ if (__n)
+ {
+ _M_check_length(size_type(0), __n, "basic_string::append");
+ const size_type __len = __n + this->size();
+ if (__len > this->capacity() || _M_rep()->_M_is_shared())
+ this->reserve(__len);
+ _M_assign(_M_data() + this->size(), __n, __c);
+ _M_rep()->_M_set_length_and_sharable(__len);
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>&
+ basic_string<_CharT, _Traits, _Alloc>::
+ append(const basic_string& __str)
+ {
+ const size_type __size = __str.size();
+ if (__size)
+ {
+ const size_type __len = __size + this->size();
+ if (__len > this->capacity() || _M_rep()->_M_is_shared())
+ this->reserve(__len);
+ _M_copy(_M_data() + this->size(), __str._M_data(), __size);
+ _M_rep()->_M_set_length_and_sharable(__len);
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>&
+ basic_string<_CharT, _Traits, _Alloc>::
append(const _CharT* __s, size_type __n)
{
__glibcxx_requires_string_len(__s, __n);