|
Boost Users : |
From: t. scott urban (scottu_at_[hidden])
Date: 2005-02-11 15:19:29
On Sat, 2005-02-12 at 06:29 +1100, Matt Hurd wrote:
> On Thu, 10 Feb 2005 18:47:11 -0800, t. scott urban
> <scottu_at_[hidden]> wrote:
> > On Thu, 2005-02-10 at 18:48 +0100, Chateauneu Remi wrote:
> > > I'm working on an application with many std::string concatenations,
> > > everywhere. This is consuming a lot of CPU resources, due to temporary
> > > strings, memory allocation, etc... Due to the size of the existing code, it
> > > is not possible to make big changes.
> > >
> > > I tried first to transform these kind of expressions:
> > > std::string a = b + c + d + e ;
> > >
> > > ... into ...
> > >
> > > std::string a(b);
> > > a += c ;
> > > a += d ;
> > > a += e ;
> >
> > It's a little ugly, but you can do
> >
> > std::string a;
> > a.reserve (b.size () + c.size () + d.size ());
> > a += b += c += d;
>
> That's about as fast as you can do.
Yep, I borked the last line though:
a += b; a += c; a+= d;
> If stl library authors used
> expression templates you do this just as fast with a = b + c + d + e;
> See round about here
> http://lists.boost.org/MailArchives/boost/msg55339.php and
> http://lists.boost.org/MailArchives/boost/msg55341.php and an
> alternative though which may be better
> http://lists.boost.org/MailArchives/boost/msg55413.php
interesting.
-- t. scott urban <scottu_at_[hidden]>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net