incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <Farid_Zari...@epam.com>
Subject RE: [PATCH] for STDCXX-491 - string::push_back() slow
Date Tue, 24 Jul 2007 17:16:07 GMT
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Tuesday, July 24, 2007 7:40 AM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: [PATCH] for STDCXX-491 - string::push_back() slow
> 
> mark.g.brown wrote:
> > Hi all,
> > 
> > The attached simple patch speeds up push_back() nearly six times 
> > relative to stdcxx 4.1.3 and makes it more than twice faster that 
> > gcc's.
> 
> Let me test your patch for regressions and if it passes I'll 
> commit it tomorrow.

  I see the difference between the old push_back() behavior and after
this patch.
The append (size_type (1), __c); also appends terminating NULL character
(string.cc, line 472). Below is the corrections to the patch:

> >  template <class _CharT, class _Traits , class _Allocator>  inline 
> > void basic_string<_CharT, _Traits, _Allocator>::
> > +push_back (value_type __c)
> > +{
> > +    const size_type __size = size () + 1;
> > +
> > +    if (   capacity () < __size
> > +        || size_type (1) < size_type (_C_pref ()->_C_get_ref ()))
> > +        append (1, __c);
> > +    else {
> > +        traits_type::assign (_C_data [size ()], __c);
                // append the terminating NUL character
                traits_type::assign (_C_data [__size], value_type ());
> > +        _C_pref ()->_C_size._C_size = __size;
> > +    }
> > +}

Farid.

Mime
View raw message