QCString -> QByteArray

David Faure faure at kde.org
Mon Feb 12 15:10:50 CET 2007


On Monday 12 February 2007, David Faure wrote:
> On Monday 12 February 2007, David Faure wrote:
> >        mBodyNew.duplicate( aStr );
> >        mBodyNew.truncate( mBodyNew.size() -1 );
> 
> Actuallly the correct code (in case aStr is null) is
> 
>        mBodyNew.duplicate( aStr );
>        if ( mBodyNew.size() > 0 )
>            mBodyNew.truncate( mBodyNew.size() -1 );

In fact all this assumes that length() == size()-1. Which is the case when not doing weird
things with the QCString (like resizing it and leaving the \0 where it was, etc.)

Which makes the fastest code:
       if ( aStr.size() )
           mBodyOld.duplicate( aStr.data(), aStr.size()-1 );
       else
           mBodyOld.resize(0);

QByteArray.duplicate(data,size-1) took 51 milliseconds.

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).


More information about the Kde-optimize mailing list