SVN commit 636466 by dfaure: Less parsing when copying a message (-> faster). As discussed with Ingo. This is part 3/3 of the fixes for kolab issue1222. M +2 -4 kmcommands.cpp M +2 -2 kmfilteraction.cpp M +15 -29 kmmessage.cpp M +2 -2 kmmessage.h --- branches/KDE/3.5/kdepim/kmail/kmcommands.cpp #636465:636466 @@ -690,9 +690,8 @@ return Failed; // Take a copy of the original message, which remains unchanged. - KMMessage *newMsg = new KMMessage; + KMMessage *newMsg = new KMMessage( new DwMessage( *msg->asDwMessage() ) ); newMsg->setComplete( msg->isComplete() ); - newMsg->fromDwString( msg->asDwString() ); KMail::Composer *win = KMail::makeComposer(); newMsg->setTransferInProgress( false ); // From here on on, the composer owns the message. @@ -1914,12 +1913,11 @@ // imap => imap with same account list.append(msg); } else { - newMsg = new KMMessage; + newMsg = new KMMessage( new DwMessage( *msg->asDwMessage() ) ); newMsg->setComplete(msg->isComplete()); // make sure the attachment state is only calculated when it's complete if (!newMsg->isComplete()) newMsg->setReadyToShow(false); - newMsg->fromDwString(msg->asDwString()); newMsg->setStatus(msg->status()); if (srcFolder && !newMsg->isComplete()) --- branches/KDE/3.5/kdepim/kmail/kmfilteraction.cpp #636465:636466 @@ -22,6 +22,7 @@ #include #include using KPIM::CollectingProcess; +#include #include "kmfawidgets.h" #include "folderrequester.h" using KMail::FolderRequester; @@ -1381,8 +1382,7 @@ return ErrorButGoOn; // copy the message 1:1 - KMMessage* msgCopy = new KMMessage; - msgCopy->fromDwString(msg->asDwString()); + KMMessage* msgCopy = new KMMessage( new DwMessage( *msg->asDwMessage() ) ); int index; int rc = mFolder->addMsg(msgCopy, &index); --- branches/KDE/3.5/kdepim/kmail/kmmessage.cpp #636465:636466 @@ -88,21 +88,11 @@ //----------------------------------------------------------------------------- KMMessage::KMMessage(DwMessage* aMsg) - : KMMsgBase(), - mMsg(aMsg), - mNeedsAssembly(true), - mDecodeHTML(false), - mOverrideCodec(0), - mFolderOffset( 0 ), - mMsgSize(0), - mMsgLength( 0 ), - mDate( 0 ), - mEncryptionState( KMMsgEncryptionStateUnknown ), - mSignatureState( KMMsgSignatureStateUnknown ), - mMDNSentState( KMMsgMDNStateUnknown ), - mUnencryptedMsg(0), - mLastUpdated( 0 ) + : KMMsgBase() { + init( aMsg ); + // aMsg might need assembly + mNeedsAssembly = true; } //----------------------------------------------------------------------------- @@ -139,10 +129,14 @@ assign( other ); } -void KMMessage::init() +void KMMessage::init( DwMessage* aMsg ) { mNeedsAssembly = false; + if ( aMsg ) { + mMsg = aMsg; + } else { mMsg = new DwMessage; + } mOverrideCodec = 0; mDecodeHTML = false; mComplete = true; @@ -295,7 +289,7 @@ } //----------------------------------------------------------------------------- -const DwMessage *KMMessage::asDwMessage() +const DwMessage* KMMessage::asDwMessage() { if (mNeedsAssembly) { @@ -313,11 +307,7 @@ QByteArray KMMessage::asSendableString() const { - KMMessage msg; - // Much faster than msg.fromDwString(asDwString()): - delete msg.mMsg; - msg.mMsg = new DwMessage( *mMsg ); - + KMMessage msg( new DwMessage( *this->mMsg ) ); msg.removePrivateHeaderFields(); msg.removeHeaderField("Bcc"); return KMail::Util::ByteArray( msg.asDwString() ); // and another copy again! @@ -325,10 +315,7 @@ QCString KMMessage::headerAsSendableString() const { - KMMessage msg; - // Much faster than msg.fromDwString(asDwString()): - delete msg.mMsg; - msg.mMsg = new DwMessage( *mMsg ); + KMMessage msg( new DwMessage( *this->mMsg ) ); msg.removePrivateHeaderFields(); msg.removeHeaderField("Bcc"); return msg.headerAsString().latin1(); @@ -1111,12 +1098,10 @@ KMMessage* KMMessage::createRedirect( const QString &toStr ) { - KMMessage* msg = new KMMessage; + // copy the message 1:1 + KMMessage* msg = new KMMessage( new DwMessage( *this->mMsg ) ); KMMessagePart msgPart; - // copy the message 1:1 - msg->fromDwString(this->asDwString()); - uint id = 0; QString strId = msg->headerField( "X-KMail-Identity" ).stripWhiteSpace(); if ( !strId.isEmpty()) @@ -1201,6 +1186,7 @@ // preserved if ( type() == DwMime::kTypeMultipart || ( type() == DwMime::kTypeText && subtype() == DwMime::kSubtypePlain ) ) { + // ## slow, we could probably use: delete msg->mMsg; msg->mMsg = new DwMessage( this->mMsg ); msg->fromDwString( this->asDwString() ); // remember the type and subtype, initFromMessage sets the contents type to // text/plain, via initHeader, for unclear reasons --- branches/KDE/3.5/kdepim/kmail/kmmessage.h #636465:636466 @@ -208,7 +208,7 @@ /** Parse the string and create this message from it. */ void fromDwString(const DwString& str, bool setStatus=FALSE); void fromString(const QCString& str, bool setStatus=FALSE); - void fromByteArray( const QByteArray & ba, bool setStatus=false ); + void fromByteArray(const QByteArray & ba, bool setStatus=false); /** Return the entire message contents in the DwString. This function is *fast* even for large message since it does *not* involve a @@ -858,7 +858,7 @@ private: /** Initialization shared by the ctors. */ - void init(); + void init( DwMessage* aMsg = 0 ); /** Assign the values of @param other to this message. Used in the copy c'tor. */ void assign( const KMMessage& other );