[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdev-python] /: cache custom includes in main thread
From:       Sven Brauch <svenbrauch () googlemail ! com>
Date:       2015-01-21 17:35:44
Message-ID: E1YDzBw-0003jc-Hc () scm ! kde ! org
[Download RAW message or body]

Git commit 6ceb1bee7efb5e05d17a0242b1bc710cee8d6e17 by Sven Brauch, on behalf of \
Radek Novacek. Committed on 18/01/2015 at 09:15.
Pushed by brauch into branch 'master'.

cache custom includes in main thread

Sven Brauch: added a mutex locker to make this thread-safe
Refactoring of the Helper stuff should be done in near future to
avoid all the statics.
REVIEW:122164

M  +1    -0    CMakeLists.txt
M  +0    -1    duchain/CMakeLists.txt
M  +4    -7    duchain/helpers.cpp
M  +2    -0    duchain/helpers.h
M  +18   -1    pythonparsejob.cpp
M  +1    -0    pythonparsejob.h

http://commits.kde.org/kdev-python/6ceb1bee7efb5e05d17a0242b1bc710cee8d6e17

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6488620..95d2092 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -89,6 +89,7 @@ add_library(kdevpythonlanguagesupport MODULE \
${kdevpythonlanguagesupport_PART_SR  target_link_libraries(kdevpythonlanguagesupport
     KDev::Interfaces
     KDev::Language
+    KDev::Util
     KF5::ThreadWeaver
     KF5::TextEditor
     KF5::KDELibs4Support
diff --git a/duchain/CMakeLists.txt b/duchain/CMakeLists.txt
index 2c876b4..9faa2b9 100644
--- a/duchain/CMakeLists.txt
+++ b/duchain/CMakeLists.txt
@@ -1,7 +1,6 @@
 
 include_directories(${CMAKE_CURRENT_BINARY_DIR}
     ${CMAKE_CURRENT_SOURCE_DIR}
-    ${KDEVELOP_INCLUDE_DIR}
     )
 
 set(duchain_SRCS
diff --git a/duchain/helpers.cpp b/duchain/helpers.cpp
index a252d7c..cea55db 100644
--- a/duchain/helpers.cpp
+++ b/duchain/helpers.cpp
@@ -42,7 +42,6 @@
 #include <interfaces/idocumentcontroller.h>
 #include <interfaces/ipartcontroller.h>
 #include <util/path.h>
-#include <project/projectmodel.h>
 
 #include <shell/partcontroller.h>
 
@@ -55,18 +54,18 @@
 #include "kdevpythonversion.h"
 #include <language/duchain/types/typeutils.h>
 
-#include <custom-definesandincludes/idefinesandincludesmanager.h>
-
 using namespace KDevelop;
 
 namespace Python {
 
 QList<QUrl> Helper::cachedSearchPaths;
+QList<QUrl> Helper::cachedCustomIncludes;
 QStringList Helper::dataDirs;
 QString Helper::documentationFile;
 DUChainPointer<TopDUContext> Helper::documentationFileContext = \
DUChainPointer<TopDUContext>(0);  QStringList Helper::correctionFileDirs;
 QString Helper::localCorrectionFileDir;
+QMutex Helper::cacheMutex;
 
 void Helper::scheduleDependency(const IndexedString& dependency, int \
betterThanPriority)  {
@@ -401,16 +400,14 @@ QUrl Helper::getLocalCorrectionFile(const QUrl& document)
     
 QList<QUrl> Helper::getSearchPaths(const QUrl& workingOnDocument)
 {
+    QMutexLocker lock(&Helper::cacheMutex);
     QList<QUrl> searchPaths;
     // search in the projects, as they're packages and likely to be installed or \
added to PYTHONPATH later  // and also add custom include paths that are defined in \
                the projects
-    IDefinesAndIncludesManager* iface = IDefinesAndIncludesManager::manager();
     foreach  (IProject* project, ICore::self()->projectController()->projects() ) {
         searchPaths.append(project->path().path());
-        foreach (Path path, iface->includes(project->projectItem())) {
-            searchPaths.append(path.toUrl());
-        }
     }
+    searchPaths.append(cachedCustomIncludes);
     
     foreach ( const QString& path, getDataDirs() ) {
         searchPaths.append(QUrl::fromLocalFile(path));
diff --git a/duchain/helpers.h b/duchain/helpers.h
index d021241..547c563 100644
--- a/duchain/helpers.h
+++ b/duchain/helpers.h
@@ -64,7 +64,9 @@ public:
     static QUrl getCorrectionFile(const QUrl& document);
     static QUrl getLocalCorrectionFile(const QUrl& document);
 
+    static QMutex cacheMutex;
     static QList<QUrl> cachedSearchPaths;
+    static QList<QUrl> cachedCustomIncludes;
 
     static AbstractType::Ptr extractTypeHints(AbstractType::Ptr type, TopDUContext* \
current);  
diff --git a/pythonparsejob.cpp b/pythonparsejob.cpp
index cc50eeb..3571ed2 100644
--- a/pythonparsejob.cpp
+++ b/pythonparsejob.cpp
@@ -29,6 +29,7 @@
 #include "checks/controlflowgraphbuilder.h"
 #include "checks/dataaccessvisitor.h"
 #include "kshell.h"
+#include "duchain/helpers.h"
 
 #include <language/duchain/duchainlock.h>
 #include <language/duchain/duchain.h>
@@ -45,7 +46,10 @@
 #include <interfaces/icore.h>
 #include <interfaces/ilanguagecontroller.h>
 #include <interfaces/idocumentcontroller.h>
+#include <interfaces/iprojectcontroller.h>
 #include <util/foregroundlock.h>
+#include <project/projectmodel.h>
+#include <util/path.h>
 
 #include <ktexteditor/document.h>
 
@@ -58,6 +62,8 @@
 #include <klocale.h>
 #include <KConfigGroup>
 
+#include <custom-definesandincludes/idefinesandincludesmanager.h>
+
 using namespace KDevelop;
 
 namespace Python
@@ -68,6 +74,12 @@ ParseJob::ParseJob(const IndexedString &url, ILanguageSupport* \
languageSupport)  , m_ast(0)
         , m_duContext(0)
 {
+    IDefinesAndIncludesManager* iface = IDefinesAndIncludesManager::manager();
+    foreach  (IProject* project, ICore::self()->projectController()->projects() ) {
+        foreach (Path path, iface->includes(project->projectItem(), \
IDefinesAndIncludesManager::UserDefined)) { +            \
m_cachedCustomIncludes.append(path.toUrl()); +        }
+    }
 }
 
 ParseJob::~ParseJob()
@@ -92,7 +104,12 @@ void ParseJob::run(ThreadWeaver::JobPointer self, \
ThreadWeaver::Thread* thread)  // lock the URL so no other parse job can run on this \
document  QReadLocker parselock(languageSupport()->parseLock());
     UrlParseLock urlLock(document());
-    
+
+    {
+        QMutexLocker lock(&Helper::cacheMutex);
+        Helper::cachedCustomIncludes = m_cachedCustomIncludes;
+    }
+
     readContents();
     
     if ( !(minimumFeatures() & TopDUContext::ForceUpdate || minimumFeatures() & \
                Rescheduled) ) {
diff --git a/pythonparsejob.h b/pythonparsejob.h
index fa1b4a9..6b59176 100644
--- a/pythonparsejob.h
+++ b/pythonparsejob.h
@@ -63,6 +63,7 @@ protected:
     virtual void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread* thread) \
override;  
 private:
+    QList<QUrl> m_cachedCustomIncludes;
     CodeAst::Ptr m_ast;
     bool m_readFromDisk;
     KDevelop::ReferencedTopDUContext m_duContext;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic