[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Sat Oct 13 11:43:46 UTC 2012
SVN commit 1320290 by kuemmel:
simplify FileBuffer
use one size for all file buffers
M +8 -9 asciisource.cpp
M +2 -3 asciisource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320289:1320290
@@ -191,7 +191,7 @@
AsciiSource::AsciiSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e) :
Kst::DataSource(store, cfg, filename, type),
_rowIndex(),
- _fileBuffer(new FileBuffer<KST_PREALLOC>),
+ _fileBuffer(new FileBuffer),
is(new DataInterfaceAsciiString(*this)),
iv(new DataInterfaceAsciiVector(*this))
{
@@ -336,7 +336,6 @@
//-------------------------------------------------------------------------------------------
-#define MAXBUFREADLEN KST_PREALLOC
Kst::Object::UpdateType AsciiSource::internalDataSourceUpdate(bool read_completely)
{
MeasureTime t("AsciiSource::internalDataSourceUpdate: " + _filename);
@@ -382,7 +381,7 @@
}
_byteLength = file.size();
- FileBuffer<MAXBUFREADLEN + 1> buf;
+ FileBuffer buf;
buf._array->resize(buf._array->capacity());
buf._bufferedS = _rowIndex[_numFrames];
buf._bufferedN = 0;
@@ -393,12 +392,12 @@
//bufstart += bufread;
buf._bufferedS = _rowIndex[_numFrames]; // always read from the start of a line
- buf._bufferedN = readFromFile(file, buf, buf._bufferedS, _byteLength - buf._bufferedS, MAXBUFREADLEN);
+ buf._bufferedN = readFromFile(file, buf, buf._bufferedS, _byteLength - buf._bufferedS, KST_PREALLOC - 1);
#ifdef KST_DONT_CHECK_INDEX_IN_DEBUG
const char* bufferData = buf.constData();
const char* buffer = bufferData;
#else
- QVarLengthArray<char, KST_PREALLOC + 1>& bufferData = *buf._array;
+ FileBuffer::Array& bufferData = *buf._array;
const char* buffer = bufferData.data();
#endif
@@ -425,7 +424,7 @@
}
}
- } while (buf._bufferedN == MAXBUFREADLEN && read_completely);
+ } while (buf._bufferedN == KST_PREALLOC - 1 && read_completely);
_rowIndex.resize(_numFrames+1);
@@ -451,7 +450,7 @@
_rowIndex[_numFrames] = row_start;
++_numFrames;
if (_numFrames >= _rowIndex.size()) {
- _rowIndex.resize(_rowIndex.size() + MAXBUFREADLEN);
+ _rowIndex.resize(_rowIndex.size() + KST_PREALLOC - 1);
}
new_data = true;
row_start = row_offset+i;
@@ -492,10 +491,10 @@
void AsciiSource::clearFileBuffer(bool forceDelete)
{
// force deletion of internal allocated memory if any
- const int memoryOnStack = sizeof(FileBuffer<KST_PREALLOC>::Array) - sizeof(QVarLengthArray<char, 0>);
+ const int memoryOnStack = sizeof(FileBuffer::Array) - sizeof(QVarLengthArray<char, 0>);
if (forceDelete || _fileBuffer->_array->capacity() > memoryOnStack) {
delete _fileBuffer->_array;
- _fileBuffer->_array = new FileBuffer<KST_PREALLOC>::Array;
+ _fileBuffer->_array = new FileBuffer::Array;
}
_fileBuffer->_bufferedS = -10;
_fileBuffer->_bufferedN = -10;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1320289:1320290
@@ -86,10 +86,9 @@
#define KST_PREALLOC 1 * 1024 * 1024
#endif
- template<int S>
struct FileBuffer
{
- typedef QVarLengthArray<char, S> Array;
+ typedef QVarLengthArray<char, KST_PREALLOC> Array;
FileBuffer() : _array(new Array), _bufferedS(-10), _bufferedN(-10) {}
~FileBuffer() { delete _array; }
@@ -105,7 +104,7 @@
void clearFileBuffer(bool forceDelete = false);
};
- FileBuffer<KST_PREALLOC>* _fileBuffer;
+ FileBuffer* _fileBuffer;
QVarLengthArray<int, KST_PREALLOC> _rowIndex;
More information about the Kst
mailing list