[Kst] branches/work/kst/portto4/kst/src

Barth Netterfield netterfield at astro.utoronto.ca
Wed Dec 16 05:52:55 CET 2009


SVN commit 1062805 by netterfield:


Only read the first part of an ascii file the first time through,
to avoid delaying datasource selection widgets.

This would fix Bug 215931, except that the qimagesource, which uses
QImage, reads the entire file to decide if it is compatible,
so there is still a (shorter) delay in reading very long
ascii files.

CCBUG: 215931



 M  +5 -2      datasources/ascii/ascii.cpp  
 M  +9 -0      datasources/qimagesource/qimagesource.cpp  
 M  +14 -6     libkst/datasource.cpp  


--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.cpp #1062804:1062805
@@ -319,6 +319,7 @@
 
 #define MAXBUFREADLEN 32768
 Kst::Object::UpdateType AsciiSource::internalDataSourceUpdate() {
+
   if (!_haveHeader) {
     _haveHeader = initRowIndex();
     if (!_haveHeader) {
@@ -358,7 +359,8 @@
   char tmpbuf[MAXBUFREADLEN+1];
   QByteArray delbytes = _config->_delimiters.toLatin1();
   const char *del = delbytes.constData();
-  
+
+  bool first_read = (_numFrames==0);
   do {
     /* Read the tmpbuffer, starting at row_index[_numFrames] */
     if (_byteLength - _rowIndex[_numFrames] > MAXBUFREADLEN) {
@@ -396,7 +398,7 @@
         has_dat = true;
       }
     }
-  } while (bufread == MAXBUFREADLEN);
+  } while ((bufread == MAXBUFREADLEN) && (!first_read));
 
   file.close();
 
@@ -966,6 +968,7 @@
                                             const QString &filename,
                                             const QString &type,
                                             const QDomElement &element) const {
+
   return new AsciiSource(store, cfg, filename, type, element);
 }
 
--- branches/work/kst/portto4/kst/src/datasources/qimagesource/qimagesource.cpp #1062804:1062805
@@ -408,8 +408,16 @@
 
 int QImageSourcePlugin::understands(QSettings *cfg, const QString& filename) const {
   Q_UNUSED(cfg)
+
+  timespec t;
+  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
+  qDebug() << "*** qimage::understands checkpoint A: " << 1.0 * t.tv_sec + 1e-9 * t.tv_nsec;
+
   QString ftype( QImageReader::imageFormat( filename ) );
 
+    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
+  qDebug() << "*** qimage::understands checkpoint B: " << 1.0 * t.tv_sec + 1e-9 * t.tv_nsec;
+
   if ( ftype.isEmpty() ) 
     return 0;
 
@@ -424,6 +432,7 @@
     if ( !filename.toLower().endsWith(".pcx") ) return 0;
   }
 
+
   return 90;
 }
 
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #1062804:1062805
@@ -201,6 +201,7 @@
 
 
 static QList<PluginSortContainer> bestPluginsForSource(const QString& filename, const QString& type) {
+
   QList<PluginSortContainer> bestPlugins;
   DataSource::init();
 
@@ -231,6 +232,7 @@
   }
 
   qSort(bestPlugins);
+
   return bestPlugins;
 }
 
@@ -239,17 +241,22 @@
 
   QList<PluginSortContainer> bestPlugins = bestPluginsForSource(filename, type);
 
-  for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
-    DataSourcePtr plugin = (*i).plugin->create(store, settingsObject, filename, QString::null, e);
-    if (plugin) {
-      return plugin;
-    }
-  }
+  DataSourcePtr plugin = bestPlugins.at(0).plugin->create(store, settingsObject, filename, QString::null, e);
+
+  return plugin;
+
+  //for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
+  //  DataSourcePtr plugin = (*i).plugin->create(store, settingsObject, filename, QString::null, e);
+  //  if (plugin) {
+  //    return plugin;
+  //  }
+  //}
   return 0L;
 }
 
 
 DataSourcePtr DataSource::loadSource(ObjectStore *store, const QString& filename, const QString& type) {
+
 #ifndef Q_WS_WIN32
   //if (filename == "stdin" || filename == "-") {
     // FIXME: what store do we put this in?
@@ -273,6 +280,7 @@
 
 DataSourcePtr DataSource::findOrLoadSource(ObjectStore *store, const QString& filename) {
   Q_ASSERT(store);
+
   DataSourcePtr dataSource = store->dataSourceList().findReusableFileName(filename);
 
   if (!dataSource) {


More information about the Kst mailing list