basic_string<>: operator+ - patch

Ryszard Kabatek rysio@rumcajs.chemie.uni-halle.de
Fri Jul 2 01:20:00 GMT 1999


Now since the reserve and _M_mutate member functions 
are fixed we can optimize the operator+.

I updated my old patch.
Below the description, the atachment contains a patch.

The operator+ for basic_string<> is curently implemented in the way:

basic_string<> __str(__lhs);
__str.append(__rhs);
return __str;


In the cases where __lhs is a string it is OK (except if __lhs is unsharable).
In other cases (_CharT, _CharT*) it leads to a reallocation.

My proposal:
create an empty string -> call reserve -> append __lhs -> append __rhs.


1999-07-02  Ryszard Kabatek <kabatek@chemie.uni-halle.de>

        * bits/basic_string.h:
          Call reserve in operator+ to avoid reallocation.


Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 (2466) Fax. +49 3461 46 2129


More information about the Libstdc++ mailing list