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

List:       kde-commits
Subject:    kdevelop/parts/doctreeview
From:       Hamish Rodda <rodda () kde ! org>
Date:       2004-02-22 3:29:19
Message-ID: 20040222032919.19B249959 () office ! kde ! org
[Download RAW message or body]

CVS commit by rodda: 

Ok, I decided this wasn't fast enough as I left it, so i've switched
to a binary format cache of the titles for the doctree, to avoid parsing
XML.

Its speed is now up to scratch :)


  M +69 -6     doctreeviewwidget.cpp   1.78


--- kdevelop/parts/doctreeview/doctreeviewwidget.cpp  #1.77:1.78
@@ -30,4 +30,5 @@
 #include <qwhatsthis.h>
 #include <qxml.h>
+#include <qdatastream.h>
 
 #include <kdebug.h>
@@ -419,4 +420,5 @@ class DocTreeTocFolder : public DocTreeI
 {
 public:
+    DocTreeTocFolder(const QString& name, KListView *parent, const QString \
                &fileName, const QString &context);
     DocTreeTocFolder(KListView *parent, const QString &fileName, const QString \
&context);  
@@ -426,5 +428,5 @@ public:
     
 private:
-    void init();
+    //void init();
     void addTocSect(DocTreeItem *parent, QDomElement childEl, uint level);
     
@@ -433,4 +435,5 @@ private:
 };
 
+#if 0
 class TocNameExtractor : public QXmlDefaultHandler
 {
@@ -471,4 +474,13 @@ private:
     bool m_titleNext;
 };
+#endif
+
+DocTreeTocFolder::DocTreeTocFolder(const QString& name, KListView *parent, const \
QString &fileName, const QString &context) +        : DocTreeItem(parent, Folder, \
fileName, context, true) +{
+    setFileName( fileName );
+    setIndexFileName( fileName );
+    setText(0, name);
+}
 
 DocTreeTocFolder::DocTreeTocFolder(KListView *parent, const QString &fileName, const \
QString &context) @@ -478,7 +490,8 @@ DocTreeTocFolder::DocTreeTocFolder(KList
     setIndexFileName( fileName );
     
-    init();
+    refresh();
 }
 
+#if 0
 void DocTreeTocFolder::init()
 {
@@ -501,4 +514,5 @@ void DocTreeTocFolder::init()
     r.parse(&s);
 }
+#endif
 
 void DocTreeTocFolder::refresh()
@@ -1074,4 +1088,37 @@ DocTreeViewWidget::DocTreeViewWidget(Doc
 
     // doctocs
+    // We're caching title only because it is a huge startup speed gain to not have \
to extract the title from the XML +    QStringList tocs = \
dirs->findAllResources("doctocs", QString::null, false, true); +    QString cache = \
dirs->findResource("data", "kdevdoctreeview/docpartcache"); +    bool regenerateCache \
= false; +    QFile cacheFile(cache);
+    if (!cache.isEmpty() && cacheFile.open(IO_ReadOnly)) {
+      QDataStream ds(&cacheFile);
+      int version;
+      ds >> version;
+      // Opening cache
+      if (version == 1) {
+        QString fileName, title;
+        while (!ds.atEnd()) {
+          ds >> fileName >> title;
+          if (tocs.contains(fileName) && QFileInfo(fileName).lastModified() < \
QFileInfo(cacheFile).lastModified()) { +            // Cache hit!
+            DocTreeTocFolder* item = new DocTreeTocFolder(title, docView, fileName, \
QString("ctx_%1").arg(fileName)); +            item->postInit();
+            folder_toc.append(item);
+            tocs.remove(fileName);
+          } else {
+            // couldn't find toc, may have been uninstalled. don't need to \
regenerate. +          }
+        }
+      } else {
+        // Incorrect cache version
+        regenerateCache = true;
+      }
+      cacheFile.close();
+    }
+    
+    if (tocs.count()) {
+      regenerateCache = true;
     QStringList tocs = dirs->findAllResources("doctocs", QString::null, false, \
                true);
     for (QStringList::Iterator tit = tocs.begin(); tit != tocs.end(); ++tit) {
@@ -1080,4 +1127,20 @@ DocTreeViewWidget::DocTreeViewWidget(Doc
         folder_toc.append(item);
     }
+    }
+    
+    if (regenerateCache) {
+      // update cache here
+      if (cache.isEmpty()) {
+        cache = dirs->saveLocation("data");
+        cache += "kdevdoctreeview/docpartcache";
+        cacheFile.setName(cache);
+      }
+      // Creating cache
+      cacheFile.open(IO_WriteOnly);
+      QDataStream ds(&cacheFile);
+      ds << 1;
+      for (DocTreeTocFolder* f = folder_toc.first(); f; f = folder_toc.next())
+        ds << f->fileName() << f->text(0);
+    }
 
     //    initKDocKDELibs();


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

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