mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user