On 09/17/2010 05:25 AM, Alex Rousskov wrote:
> On 09/03/2010 09:21 AM, Kinkie wrote:
>
> > SBuf& SBuf::append(const SBuf &S)
> > {
> > debugs(SBUF_DEBUGSECTION,7,
> > MYNAME << "this=" << (void *)this <<
> > "appending=" <<(void *)&S<<")");
> > if (!store_->canAppend(bufEnd(),S.length())) {
> > grow(length()+S.length());
> > }
>
> Please remove all such canAppend() guards. Just call grow(). It is much
> safer than risking to forget a guard. Your grow() should not reAlloc if
> growth is not needed. You may rename grow() to assureSpace() or similar
> if you prefer but do not split the growth need check and the realloc
> call in the "user" code.
The standard name for "make sure we have enough space" method is
"reserve". See std::string::reserve() documentation for what it may and
must do. Use it instead of the canAppend+grow duet.
Thank you,
Alex.
Received on Fri Sep 17 2010 - 17:28:53 MDT
This archive was generated by hypermail 2.2.0 : Fri Sep 17 2010 - 12:00:06 MDT