Database backends: fix bug, and small speedup
authorest31 <MTest31@outlook.com>
Sat, 26 Dec 2015 16:01:41 +0000 (17:01 +0100)
committerest31 <MTest31@outlook.com>
Mon, 28 Dec 2015 23:39:42 +0000 (00:39 +0100)
-> Redis backend: break from switch to fix bug
-> Dummy and redis backends: reserve the count so that creating the list is faster

src/database-dummy.cpp
src/database-redis.cpp

index 2e5de5ed11fcd57f914d1c56ffca8b78c9937a39..b38db1fb966f3c1dcbc5eddd3132b87bed4b2d45 100644 (file)
@@ -47,6 +47,7 @@ bool Database_Dummy::deleteBlock(const v3s16 &pos)
 
 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();
                        x != m_database.end(); ++x) {
                dst.push_back(getIntegerAsBlock(x->first));
index b15f546b2ec245c51d308fc3edce7960eae51cd7..196d72f251e307005bde1cb489638b333e47ee77 100644 (file)
@@ -169,10 +169,12 @@ void Database_Redis::listAllLoadableBlocks(std::vector<v3s16> &dst)
        }
        switch (reply->type) {
        case REDIS_REPLY_ARRAY:
+               dst.reserve(reply->elements);
                for (size_t i = 0; i < reply->elements; i++) {
                        assert(reply->element[i]->type == REDIS_REPLY_STRING);
                        dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str)));
                }
+               break;
        case REDIS_REPLY_ERROR:
                throw FileNotGoodException(std::string(
                        "Failed to get keys from database: ") + reply->str);