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

Peter Kümmel syntheticpp at gmx.net
Sun Jun 2 06:55:42 UTC 2013


SVN commit 1356770 by kuemmel:

use hash map for string lookup, it's much faster for many columns

 M  +2 -2      asciidatainterfaces.h  
 M  +7 -2      asciisource.cpp  
 M  +1 -0      asciisource.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatainterfaces.h #1356769:1356770
@@ -41,7 +41,7 @@
   // named elements
   QStringList list() const { return ascii._fieldList; }
   bool isListComplete() const { return ascii._fieldListComplete; }
-  bool isValid(const QString& field) const { return ascii._fieldList.contains( field ); }
+  bool isValid(const QString& field) const { return ascii._fieldLookup.contains( field ); }
 
   // T specific
   const DataVector::DataInfo dataInfo(const QString&) const;
@@ -59,7 +59,7 @@
 //-------------------------------------------------------------------------------------------
 const DataVector::DataInfo DataInterfaceAsciiVector::dataInfo(const QString &field) const
 {
-  if (!ascii._fieldList.contains(field))
+  if (!ascii._fieldLookup.contains(field))
     return DataVector::DataInfo();
 
   return DataVector::DataInfo(ascii._reader.numberOfFrames(), 1);
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1356769:1356770
@@ -98,6 +98,7 @@
   _fieldListComplete = false;
   
   _fieldList.clear();
+  _fieldLookup.clear();
   _scalarList.clear();
   _strings.clear();
   
@@ -173,6 +174,10 @@
     }
     _fieldListComplete = _fieldList.count() > 1;
     
+    _fieldLookup.clear();
+    for (int i = 0; i < _fieldList.size(); i++)
+        _fieldLookup[_fieldList[i]] = i;
+
     // Re-update the scalar list since we have one now
     _scalarList = scalarListFor(_filename, &_config);
   }
@@ -200,8 +205,8 @@
 //-------------------------------------------------------------------------------------------
 int AsciiSource::columnOfField(const QString& field) const
 {
-  if (_fieldList.contains(field)) {
-    return _fieldList.indexOf(field);
+  if (_fieldLookup.contains(field)) {
+    return _fieldLookup[field];
   } 
   
   if (_fieldListComplete) {
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1356769:1356770
@@ -86,6 +86,7 @@
     QStringList _scalarList;
     QMap<QString, QString> _strings;
     QStringList _fieldList;
+    QHash<QString, int> _fieldLookup;
     QMap<QString, QString> _fieldUnits;
 
     bool useThreads() const;


More information about the Kst mailing list