[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Sun Oct 14 12:03:14 UTC 2012
SVN commit 1320477 by kuemmel:
FileBuffer: one clear is enough
M +3 -3 asciifilebuffer.cpp
M +1 -2 asciifilebuffer.h
M +7 -7 asciisource.cpp
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.cpp #1320476:1320477
@@ -20,17 +20,17 @@
_array->resize(bytes);
} catch (const std::bad_alloc&) {
// work around Qt bug
- clearFileBuffer(true);
+ clear(true);
return false;
}
return true;
}
//-------------------------------------------------------------------------------------------
-void AsciiFileBuffer::clearFileBuffer(bool forceDelete)
+void AsciiFileBuffer::clear(bool forceDeletingArray)
{
// force deletion of heap allocated memory if any
- if (forceDelete || _array->capacity() > Prealloc) {
+ if (forceDeletingArray || _array->capacity() > Prealloc) {
delete _array;
_array = new Array;
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.h #1320476:1320477
@@ -39,7 +39,6 @@
int _bufferedS;
int _bufferedN;
- inline void clear() { _array->clear(); }
inline int size() const { return _array->size(); }
inline int capacity() const { return _array->capacity(); }
inline char* data() { return _array->data(); }
@@ -48,7 +47,7 @@
inline const Array& constArray() const{ return *_array; }
bool resize(int size);
- void clearFileBuffer(bool forceDelete = false);
+ void clear(bool forceDeletingArray = false);
private:
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320476:1320477
@@ -94,7 +94,7 @@
void AsciiSource::reset()
{
// forget about cached data
- _fileBuffer->clearFileBuffer();
+ _fileBuffer->clear();
reader.rowIndex().clear();
_valid = false;
@@ -180,7 +180,7 @@
MeasureTime t("AsciiSource::internalDataSourceUpdate: " + _filename);
// forget about cached data
- _fileBuffer->clearFileBuffer();
+ _fileBuffer->clear();
if (!_haveHeader) {
_haveHeader = initRowIndex();
@@ -257,12 +257,12 @@
// reading whole file into memory failed
// find a smaller allocatable size
- _fileBuffer->clearFileBuffer();
+ _fileBuffer->clear();
int realloc_size = n / 4;
while (!_fileBuffer->resize(realloc_size) && realloc_size > 0) {
realloc_size /= 2;
}
- _fileBuffer->clearFileBuffer();
+ _fileBuffer->clear();
if (realloc_size == 0) {
QMessageBox::warning(0, "Error while reading ascii file", "File could not be read because not enough memory is available.");
return 0;
@@ -272,18 +272,18 @@
int start = s;
n_read = 0;
while (n_read < n) {
- _fileBuffer->clearFileBuffer();
+ _fileBuffer->clear();
int to_read = n_read + realloc_size < n ? realloc_size : n - n_read;
n_read += readField(v + start, field, n_read, to_read, succcess);
if (!succcess) {
- _fileBuffer->clearFileBuffer();
+ _fileBuffer->clear();
QMessageBox::warning(0, "Error while reading ascii file", "The file was only read partially not enough memory is available.");
return n_read;
}
start += to_read;
}
// don't buffer partial files
- _fileBuffer->clearFileBuffer();
+ _fileBuffer->clear();
return n_read;
}
More information about the Kst
mailing list