[Patch] Batch of basic_string correctness and performance work

Paolo Carlini pcarlini@suse.de
Sun Oct 24 17:33:00 GMT 2004


Hi,

the below is the results of few days of coding and thinkering... The
inspiration, as often happens, is from Nathan: recenrly he hinted to
tweak inlining and avoid always using the heavy and non-inlinable
_M_mutate.

Then, I noticed that the existing append in basic_string.tcc were
already rather close to this objective if only I could avoid calling
_M_replace_safe and make the result sufficiently simple to be inlinable.
This I did (together with a correctness fix, noticed during the work,
and the addition of a few helpers, that clean-up remarkably the code).

To give you an idea:

21_strings/string_append.cc
===========================
current
-------
Execution time of 10000000 string::append(char) calls: 0.26 sec.
Execution time of 10000000 string::append(const string&) calls: 0.49 sec.

patched
-------
Execution time of 10000000 string::append(char) calls: 0.14 sec.
Execution time of 10000000 string::append(const string&) calls: 0.14 sec.

Also, I verified, that a typical use of +=(_CharT), in extract_float,
actually benefited from this kind of work:

27_io/ifstream_extract_float.cc (p = 12)
========================================
current
-------
14.130u 0.060s 0:14.25 99.5%    0+0k 0+0io 235pf+0w

patched
-------
13.570u 0.080s 0:13.70 99.6%    0+0k 0+0io 238pf+0w

indeed, besides the numbers, operations on strings almost disappeared 
from the
profile: unpatched mainline shows _M_mutate in the 4th position (after the
extract_float code itself, memchr and strtof), whereas now the first one is
_Alloc_hider::_Alloc_hider in the 9th position.

Various versions regtested x86/ia64-linux many times: I plan to 
n-th-check the
code again during the next few hours and commit tomorrow barring objections.

Paolo.

/////////////////
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CL_string
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041024/c1ac26d8/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch_string_14
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041024/c1ac26d8/attachment-0001.ksh>


More information about the Libstdc++ mailing list