Speed up CSV import by not querying the stream position

Avoid querying the position in the text stream using Qt's pos() function
to update the progress dialog. Instead keep track of the stream position
manually. This is possible here because we don't ever seek in the file.
In result, this speeds up the CSV import dramatically.
This commit is contained in:
Martin Kleusberg
2017-11-05 12:40:32 +01:00
parent a03a901051
commit ed9fda28ea

View File

@@ -140,9 +140,11 @@ CSVParser::ParserResult CSVParser::parse(csvRowFunction insertFunction, QTextStr
};
FieldBufferDealloc dealloc(record);
qint64 bufferPos = 0;
while(!stream.atEnd())
{
sBuffer = stream.read(m_nBufferSize).toUtf8();
bufferPos += sBuffer.length();
auto sBufferEnd = sBuffer.constEnd();
for(auto it = sBuffer.constBegin(); it != sBufferEnd; ++it)
@@ -276,7 +278,7 @@ CSVParser::ParserResult CSVParser::parse(csvRowFunction insertFunction, QTextStr
if(m_pCSVProgress && parsedRows % 100 == 0)
{
if(!m_pCSVProgress->update(stream.pos()))
if(!m_pCSVProgress->update(bufferPos))
return ParserResult::ParserResultCancelled;
}
}