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

Peter Kümmel syntheticpp at gmx.net
Sun Oct 14 12:03:25 UTC 2012


SVN commit 1320482 by kuemmel:

Don't store rows but byte read in buffer

set buffer values in readFromFile()

 M  +8 -2      asciidatareader.cpp  
 M  +2 -3      asciisource.cpp  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.cpp #1320481:1320482
@@ -93,6 +93,8 @@
 //-------------------------------------------------------------------------------------------
 int AsciiDataReader::readFromFile(QFile& file, AsciiFileBuffer& buffer, int start, int bytesToRead, int maximalBytes)
 {
+  buffer.setRead(0);
+
   if (maximalBytes == -1) {
     if (!buffer.resize(bytesToRead + 1))
       return 0;
@@ -105,7 +107,11 @@
   int bytesRead = file.read(buffer.data(), bytesToRead);
   if (!buffer.resize(bytesRead + 1))
     return 0;
+
   buffer.data()[bytesRead] = '\0';
+  buffer.setStart(start);
+  buffer.setRead(bytesRead);
+
   return bytesRead;
 }
 
@@ -120,8 +126,8 @@
     // Read the tmpbuffer, starting at row_index[_numFrames]
     buf.clear();
 
-    buf.setStart(_rowIndex[numFrames]); // always read from the start of a line
-    buf.setRead(readFromFile(file, buf, buf.start(), _byteLength - buf.start(), AsciiFileBuffer::Prealloc - 1));
+    // always read from the start of a line
+    readFromFile(file, buf, _rowIndex[numFrames], _byteLength - buf.start(), AsciiFileBuffer::Prealloc - 1);
     
     if (_config._delimiters.value().size() == 0) {
       const NoDelimiter comment_del;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320481:1320482
@@ -314,7 +314,8 @@
     return 0;
   }
   
-  if ((s != _fileBuffer->start()) || (n != _fileBuffer->read())) {
+  // check if the already in buffer
+  if ((s != _fileBuffer->start()) || (bufread != _fileBuffer->read())) {
     QFile file(_filename);
     if (!openValidFile(file)) {
       return 0;
@@ -327,8 +328,6 @@
       success = false;
       return 0;
     }
-    _fileBuffer->setStart(s);
-    _fileBuffer->setRead(n);
   }
   
   return reader.readField(_fileBuffer, col, bufstart, bufread, v, field, s, n);


More information about the Kst mailing list