[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdevplatform/language
From: David Nolden <david.nolden.kde () art-master ! de>
Date: 2009-11-22 23:54:30
Message-ID: 1258934070.295087.28141.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1053020 by zwabel:
- Handle the ModificationRevisionSet "needsUpdate" cache more intelligently: Don't \
clear the cache on every significant ModificationRevisionSet operation, instead just \
remove dead entries in realtime, and use the ModificationRevision timeout for the \
cache lifetime.
- Increase the timeout to 30 seconds, so the caching really shows an effect.
This improves the speed of preprocessing/parsing in C++, and especially the speed of \
checking whether all top-contexts are still up to date.
M +5 -1 duchain/topducontext.cpp
M +3 -3 editor/modificationrevision.cpp
M +4 -1 editor/modificationrevision.h
M +25 -16 editor/modificationrevisionset.cpp
--- trunk/KDE/kdevplatform/language/duchain/topducontext.cpp #1053019:1053020
@@ -899,7 +899,11 @@
parsingEnvironmentFile()->setFeatures(features());
}
-void TopDUContext::setParsingEnvironmentFile(ParsingEnvironmentFile* file) {
+void TopDUContext::setParsingEnvironmentFile(ParsingEnvironmentFile* file)
+{
+ if(m_local->m_file) //Clear the "feature satisfaction" cache
+ m_local->m_file->setFeatures(Empty);
+
//We do not enforce a duchain lock here, since this is also used while loading a \
top-context m_local->m_file = KSharedPtr<ParsingEnvironmentFile>(file);
--- trunk/KDE/kdevplatform/language/editor/modificationrevision.cpp #1053019:1053020
@@ -46,10 +46,10 @@
#include "modificationrevisionset.h"
#include <sys/time.h>
-const int cacheModTimeForSeconds = 2;
-
namespace KDevelop {
+const int cacheModificationTimesForSeconds = 30;
+
struct IndexedStringHash {
uint operator() (const KDevelop::IndexedString& str) const {
return str.hash();
@@ -94,7 +94,7 @@
///Use the cache for X seconds
timeval age;
timersub(¤tTime, &(*it).second.m_readTime, &age);
- if( age.tv_sec < cacheModTimeForSeconds )
+ if( age.tv_sec < cacheModificationTimesForSeconds )
return (*it).second.m_modificationTime;
}
--- trunk/KDE/kdevplatform/language/editor/modificationrevision.h #1053019:1053020
@@ -29,6 +29,8 @@
class IndexedString;
+KDEVPLATFORMLANGUAGE_EXPORT extern const int cacheModificationTimesForSeconds;
+
/**
* Pairs together a date and a revision-number, for simpler moving around and \
comparison. Plus some convenience-functions.
* Use this to track changes to files, by storing the file-modification time and the \
editor-revision if applicable(@see KTextEditor::SmartInterface) @@ -44,7 +46,8 @@
///This is efficient, because it uses a cache to look up the modification-revision, \
caching file-system stats for some time static ModificationRevision \
revisionForFile(const IndexedString& fileName);
- ///You can use this when you want to make sure that any cached modification-time is \
discarded and it's re-read on the next access + ///You can use this when you want to \
make sure that any cached modification-time is discarded and it's re-read on the next \
access. + ///Otherwise, the modification-times are re-used for a specific amount \
of time static void clearModificationCache(const IndexedString& fileName);
///The default-revision is 1, because that is the kate smart-revision for cleanly \
opened documents
--- trunk/KDE/kdevplatform/language/editor/modificationrevisionset.cpp \
#1053019:1053020 @@ -18,9 +18,11 @@
#include "../duchain/repositories/itemrepository.h"
#include <duchain/indexedstring.h>
#include <util/setrepository.h>
+#include <time.h>
//When uncommented, the reason for needed updates is printed
// #define DEBUG_NEEDSUPDATE
+#include <sys/time.h>
namespace KDevelop {
@@ -93,21 +95,18 @@
return rep;
}
-QHash<uint, bool> needsUpdateCache;
+QHash<uint, std::pair<timeval, bool> > needsUpdateCache;
void ModificationRevisionSet::clearCache() {
QMutexLocker lock(&modificationRevisionSetMutex);
///@todo More intelligent clearing. We actually need to watch the directory for \
changes, and if there are changes, clear the cache. needsUpdateCache.clear();
-// kDebug() << "clearing cache";
}
struct FileModificationSetRepository : public Utils::BasicSetRepository {
FileModificationSetRepository() : Utils::BasicSetRepository("file modification \
sets", &KDevelop::globalItemRepositoryRegistry(), true) { }
- virtual void itemRemovedFromSets(uint index) {
- fileModificationPairRepository().deleteItem(index);
- }
+ virtual void itemRemovedFromSets(uint index);
};
//FileModificationSetRepository fileModificationSetRepository;
@@ -136,7 +135,6 @@
oldModificationTimes.staticUnref();
m_index = 0;
}
- clearCache();
}
void ModificationRevisionSet::addModificationRevision(const IndexedString& url, \
const KDevelop::ModificationRevision& revision) { @@ -168,8 +166,6 @@
if(!m_index)
return false;
- clearCache();
-
Utils::Set oldModificationTimes = Utils::Set(m_index, \
&FileModificationSetRepositoryRepresenter::repository()); Utils::Set \
newModificationTimes = oldModificationTimes;
@@ -209,10 +205,21 @@
if(!index)
return false;
- QHash<uint, bool>::const_iterator cached = needsUpdateCache.constFind(index);
- if(cached != needsUpdateCache.constEnd())
- return cached.value();
+ timeval currentTime;
+ gettimeofday(¤tTime, 0);
+ QHash<uint, std::pair<timeval, bool> >::const_iterator cached = \
needsUpdateCache.constFind(index); + if(cached != needsUpdateCache.constEnd()) {
+
+ timeval age;
+ timersub(¤tTime, &(*cached).first, &age);
+
+ if( age.tv_sec < cacheModificationTimesForSeconds )
+ {
+ return cached->second;
+ }
+ }
+
bool result = false;
const Utils::SetNodeData* nodeData = \
FileModificationSetRepositoryRepresenter::repository().nodeFromIndex(index); @@ \
-230,7 +237,7 @@
result = nodeNeedsUpdate(nodeData->leftNode) || \
nodeNeedsUpdate(nodeData->rightNode); }
- needsUpdateCache.insert(index, result);
+ needsUpdateCache.insert(index, std::make_pair(currentTime, result));
return result;
}
@@ -292,8 +299,6 @@
m_index = newModificationTimes.setIndex();
- clearCache();
-
return *this;
}
@@ -311,9 +316,13 @@
m_index = newModificationTimes.setIndex();
- clearCache();
-
return *this;
}
+void FileModificationSetRepository::itemRemovedFromSets(uint index)
+{
+ fileModificationPairRepository().deleteItem(index);
+ needsUpdateCache.remove(index);
}
+
+}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic