Database backends: fix bug, and small speedup

-> Redis backend: break from switch to fix bug
-> Dummy and redis backends: reserve the count so that creating the list is faster
This commit is contained in:
est31 2015-12-26 17:01:41 +01:00
parent 382ab969d4
commit 8a46c5df1c
2 changed files with 3 additions and 0 deletions

@ -47,6 +47,7 @@ bool Database_Dummy::deleteBlock(const v3s16 &pos)
void Database_Dummy::listAllLoadableBlocks(std::vector<v3s16> &dst) void Database_Dummy::listAllLoadableBlocks(std::vector<v3s16> &dst)
{ {
dst.reserve(m_database.size());
for (std::map<s64, std::string>::const_iterator x = m_database.begin(); for (std::map<s64, std::string>::const_iterator x = m_database.begin();
x != m_database.end(); ++x) { x != m_database.end(); ++x) {
dst.push_back(getIntegerAsBlock(x->first)); dst.push_back(getIntegerAsBlock(x->first));

@ -169,10 +169,12 @@ void Database_Redis::listAllLoadableBlocks(std::vector<v3s16> &dst)
} }
switch (reply->type) { switch (reply->type) {
case REDIS_REPLY_ARRAY: case REDIS_REPLY_ARRAY:
dst.reserve(reply->elements);
for (size_t i = 0; i < reply->elements; i++) { for (size_t i = 0; i < reply->elements; i++) {
assert(reply->element[i]->type == REDIS_REPLY_STRING); assert(reply->element[i]->type == REDIS_REPLY_STRING);
dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str))); dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str)));
} }
break;
case REDIS_REPLY_ERROR: case REDIS_REPLY_ERROR:
throw FileNotGoodException(std::string( throw FileNotGoodException(std::string(
"Failed to get keys from database: ") + reply->str); "Failed to get keys from database: ") + reply->str);