1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

DB::loadBlock copy removal & DB backend cleanup

* Remove the copy from db::loadBlock by using a pointer to the destination
* cleanup db backend, the child backend doesn't have to set their functions as virtual
This commit is contained in:
Loic Blot 2016-05-14 12:23:15 +02:00
parent decbd396df
commit 143401451c
11 changed files with 47 additions and 47 deletions

View file

@ -101,7 +101,7 @@ bool Database_Redis::saveBlock(const v3s16 &pos, const std::string &data)
return true;
}
std::string Database_Redis::loadBlock(const v3s16 &pos)
void Database_Redis::loadBlock(const v3s16 &pos, std::string *block)
{
std::string tmp = i64tos(getBlockAsInteger(pos));
redisReply *reply = static_cast<redisReply *>(redisCommand(ctx,
@ -111,12 +111,13 @@ std::string Database_Redis::loadBlock(const v3s16 &pos)
throw FileNotGoodException(std::string(
"Redis command 'HGET %s %s' failed: ") + ctx->errstr);
}
switch (reply->type) {
case REDIS_REPLY_STRING: {
std::string str(reply->str, reply->len);
*block = std::string(reply->str, reply->len);
// std::string copies the memory so this won't cause any problems
freeReplyObject(reply);
return str;
return;
}
case REDIS_REPLY_ERROR: {
std::string errstr(reply->str, reply->len);
@ -127,11 +128,13 @@ std::string Database_Redis::loadBlock(const v3s16 &pos)
"Redis command 'HGET %s %s' errored: ") + errstr);
}
case REDIS_REPLY_NIL: {
*block = "";
// block not found in database
freeReplyObject(reply);
return "";
return;
}
}
errorstream << "loadBlock: loading block " << PP(pos)
<< " returned invalid reply type " << reply->type
<< ": " << std::string(reply->str, reply->len) << std::endl;