From 4efae064bc52f8ba8f26d6b856bf7f944e48fcf4 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 5 Nov 2004 00:45:23 +0000 Subject: [PATCH] A faster method for retrieving a message without getMsg + unGetMsg (*) It simply combines the code from getMsg and readMsg, without the mMsgList.set() call. (*) Callgrind shows that unGetMsg takes time too, mostly due to strippedSubjectMD5(), so let's avoid it altogether, as discussed with Till. svn path=/branches/KDE_3_3_BRANCH/kdepim/; revision=360560 --- folderstorage.cpp | 29 ++++++++++++++++++++++++++--- folderstorage.h | 6 ++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/folderstorage.cpp b/folderstorage.cpp index 1dd5558e6..d60339d31 100644 --- a/folderstorage.cpp +++ b/folderstorage.cpp @@ -427,12 +427,10 @@ void FolderStorage::take(QPtrList msgList) //----------------------------------------------------------------------------- KMMessage* FolderStorage::getMsg(int idx) { - KMMsgBase* mb; - if(!(idx >= 0 && idx <= count())) return 0; - mb = getMsgBase(idx); + KMMsgBase* mb = getMsgBase(idx); if (!mb) return 0; #if 0 @@ -464,8 +462,33 @@ KMMessage* FolderStorage::getMsg(int idx) msg->setComplete( true ); return msg; #endif +} + +//----------------------------------------------------------------------------- +KMMessage* FolderStorage::readTemporaryMsg(int idx) +{ + if(!(idx >= 0 && idx <= count())) + return 0; + KMMsgBase* mb = getMsgBase(idx); + if (!mb) return 0; + KMMessage *msg = 0; + bool undo = mb->enableUndo(); + if (mb->isMessage()) { + // the caller will delete it, so we must make a copy it + msg = new KMMessage(*(KMMessage*)mb); + } else { + // ## Those two lines need to be moved to a virtual method for KMFolderSearch, like readMsg + msg = new KMMessage(*(KMMsgInfo*)mb); + msg->fromDwString(getDwString(idx)); + } + msg->setEnableUndo(undo); + if (msg->getMsgSerNum() == 0) { + msg->setMsgSerNum(kmkernel->msgDict()->insert(0, msg, idx)); + } + msg->setComplete( true ); + return msg; } diff --git a/folderstorage.h b/folderstorage.h index a3d4732d9..d26c5b27a 100644 --- a/folderstorage.h +++ b/folderstorage.h @@ -144,6 +144,12 @@ public: /** Checks if the message is already "gotten" with getMsg */ virtual bool isMessage(int idx); + /** Load message from file and do NOT store it, only return it. + This is equivalent to, but faster than, getMsg+unGetMsg + WARNING: the caller has to delete the returned value! + */ + virtual KMMessage* readTemporaryMsg(int idx); + /** Read a message and return a referece to a string */ virtual QCString& getMsgString(int idx, QCString& mDest) = 0;