basic_string<> - operator+

Ryszard Kabatek rysio@rumcajs.chemie.uni-halle.de
Thu Dec 30 07:30:00 GMT 1999


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-06-23  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