This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
some basic_string optimization
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: some basic_string optimization
- From: Vadim Egorov <egorovv at mailandnews dot com>
- Date: 28 Apr 2000 19:14:32 +0400
- Reply-to: libstdc++ at sourceware dot cygnus dot com
Hello,
I found that replacing a single character in a string was a bit more
expensive than I thought. Making _M_mutate call conditional made
this operation work seems improves the situation.
Regards
Vadim Egorov
2000-04-28 Vadim Egorov <egorovv@mailandnews.com>
* bits/basic_string.h (_S_construct): Swap parameter names
* bits/string.tcc: avoid unnecessary _M_mutate
Index: string.tcc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/string.tcc,v
retrieving revision 1.59
diff -c -r1.59 string.tcc
*** string.tcc 2000/03/28 04:21:42 1.59
--- string.tcc 2000/04/28 14:30:36
***************
*** 440,446 ****
__LENGTHERROR(__dmax <= __dnew);
size_type __off = __i1 - _M_ibegin();
! _M_mutate(__off, __dold, __dnew);
// Invalidated __i1, __i2
if (__dnew)
_S_copy_chars(_M_data() + __off, __j1, __j2);
--- 440,447 ----
__LENGTHERROR(__dmax <= __dnew);
size_type __off = __i1 - _M_ibegin();
! if (__dold != __dnew)
! _M_mutate(__off, __dold, __dnew);
// Invalidated __i1, __i2
if (__dnew)
_S_copy_chars(_M_data() + __off, __j1, __j2);
***************
*** 549,555 ****
size_type __n1 = __i2 - __i1;
size_type __off1 = __i1 - _M_ibegin();
__LENGTHERROR(max_size() - (this->size() - __n1) <= __n2);
! _M_mutate (__off1, __n1, __n2);
// Invalidated __i1, __i2
if (__n2)
traits_type::assign(_M_data() + __off1, __n2, __c);
--- 550,557 ----
size_type __n1 = __i2 - __i1;
size_type __off1 = __i1 - _M_ibegin();
__LENGTHERROR(max_size() - (this->size() - __n1) <= __n2);
! if (__n1 != __n2)
! _M_mutate (__off1, __n1, __n2);
// Invalidated __i1, __i2
if (__n2)
traits_type::assign(_M_data() + __off1, __n2, __c);
Index: basic_string.h
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/basic_string.h,v
retrieving revision 1.57
diff -c -r1.57 basic_string.h
*** basic_string.h 2000/04/18 21:18:15 1.57
--- basic_string.h 2000/04/28 14:31:55
***************
*** 691,697 ****
// string::iterator, _CharT*, etc.
template<class _FwdIter>
static _CharT*
! _S_construct(_FwdIter __end, _FwdIter __beg, const _Alloc& __a,
forward_iterator_tag);
static _CharT*
--- 691,697 ----
// string::iterator, _CharT*, etc.
template<class _FwdIter>
static _CharT*
! _S_construct(_FwdIter __beg, _FwdIter __end, const _Alloc& __a,
forward_iterator_tag);
static _CharT*