Speed up the loading of row data a bit

This improves the performance for loading row data with my setup by
about 10%. Incidentally, the conversion from Qt to STL containers
reduced the performance by about the same number.
This commit is contained in:
Martin Kleusberg
2019-05-02 12:34:14 +02:00
parent e16537dd9a
commit 9c0b36d7b7

View File

@@ -234,18 +234,18 @@ void RowLoader::process (Task & t)
while(!t.cancel && sqlite3_step(stmt) == SQLITE_ROW)
{
Cache::value_type rowdata;
// Construct a new row object with the right number of columns
Cache::value_type rowdata(static_cast<size_t>(num_columns));
for(int i=0;i<num_columns;++i)
{
if(sqlite3_column_type(stmt, i) == SQLITE_NULL)
// No need to do anything for NULL values because we can just use the already default constructed value
if(sqlite3_column_type(stmt, i) != SQLITE_NULL)
{
rowdata.emplace_back();
} else {
int bytes = sqlite3_column_bytes(stmt, i);
if(bytes)
rowdata.emplace_back(static_cast<const char*>(sqlite3_column_blob(stmt, i)), bytes);
rowdata[static_cast<size_t>(i)] = QByteArray(static_cast<const char*>(sqlite3_column_blob(stmt, i)), bytes);
else
rowdata.emplace_back("");
rowdata[static_cast<size_t>(i)] = "";
}
}
QMutexLocker lk(&cache_mutex);