Skip to content

Commit 8a46c5d

Browse files
committedDec 28, 2015
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
1 parent 382ab96 commit 8a46c5d

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed
 

Diff for: ‎src/database-dummy.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ bool Database_Dummy::deleteBlock(const v3s16 &pos)
4747

4848
void Database_Dummy::listAllLoadableBlocks(std::vector<v3s16> &dst)
4949
{
50+
dst.reserve(m_database.size());
5051
for (std::map<s64, std::string>::const_iterator x = m_database.begin();
5152
x != m_database.end(); ++x) {
5253
dst.push_back(getIntegerAsBlock(x->first));

Diff for: ‎src/database-redis.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ void Database_Redis::listAllLoadableBlocks(std::vector<v3s16> &dst)
169169
}
170170
switch (reply->type) {
171171
case REDIS_REPLY_ARRAY:
172+
dst.reserve(reply->elements);
172173
for (size_t i = 0; i < reply->elements; i++) {
173174
assert(reply->element[i]->type == REDIS_REPLY_STRING);
174175
dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str)));
175176
}
177+
break;
176178
case REDIS_REPLY_ERROR:
177179
throw FileNotGoodException(std::string(
178180
"Failed to get keys from database: ") + reply->str);

0 commit comments

Comments
 (0)
Please sign in to comment.