From ef0aa7d5b543b6561e1b7292b2d0a0ac43add55d Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 11 Jan 2017 22:48:14 +0100 Subject: [PATCH] Optimize SAO getStaticData by using std::string pointer instead of return copy Signed-off-by: Loic Blot --- src/content_sao.cpp | 9 ++++----- src/content_sao.h | 4 ++-- src/serverenvironment.cpp | 9 ++++++--- src/serverobject.h | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 852e2d788..bf8282af4 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -521,7 +521,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) return os.str(); } -std::string LuaEntitySAO::getStaticData() const +void LuaEntitySAO::getStaticData(std::string *result) const { verbosestream<getBasePosition(); - std::string staticdata = object->getStaticData(); + std::string staticdata = ""; + object->getStaticData(&staticdata); StaticObject s_obj(object->getType(), objectpos, staticdata); // Add to the block where the object is located in v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); @@ -1980,7 +1981,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) <getStaticData(); + std::string staticdata_new = ""; + obj->getStaticData(&staticdata_new); StaticObject s_obj(obj->getType(), objectpos, staticdata_new); block->m_static_objects.insert(id, s_obj); obj->m_static_block = blockpos_o; @@ -2020,7 +2022,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) if(obj->isStaticAllowed()) { // Create new static object - std::string staticdata_new = obj->getStaticData(); + std::string staticdata_new = ""; + obj->getStaticData(&staticdata_new); StaticObject s_obj(obj->getType(), objectpos, staticdata_new); bool stays_in_same_block = false; diff --git a/src/serverobject.h b/src/serverobject.h index 9e8b5a779..26c8b062d 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -119,10 +119,10 @@ public: when it is created (converted from static to active - actually the data is the static form) */ - virtual std::string getStaticData() + virtual void getStaticData(std::string *result) { assert(isStaticAllowed()); - return ""; + *result = ""; } /* Return false in here to never save and instead remove object