Optimize SAO getStaticData by using std::string pointer instead of return copy

Signed-off-by: Loic Blot <loic.blot@unix-experience.fr>
This commit is contained in:
Loic Blot 2017-01-11 22:48:14 +01:00 committed by Loïc Blot
parent e2dd96b432
commit ef0aa7d5b5
4 changed files with 14 additions and 12 deletions

@ -521,7 +521,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
return os.str(); return os.str();
} }
std::string LuaEntitySAO::getStaticData() const void LuaEntitySAO::getStaticData(std::string *result) const
{ {
verbosestream<<FUNCTION_NAME<<std::endl; verbosestream<<FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
@ -543,7 +543,7 @@ std::string LuaEntitySAO::getStaticData() const
writeV3F1000(os, m_velocity); writeV3F1000(os, m_velocity);
// yaw // yaw
writeF1000(os, m_yaw); writeF1000(os, m_yaw);
return os.str(); *result = os.str();
} }
int LuaEntitySAO::punch(v3f dir, int LuaEntitySAO::punch(v3f dir,
@ -918,10 +918,9 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
return os.str(); return os.str();
} }
std::string PlayerSAO::getStaticData() const void PlayerSAO::getStaticData(std::string *result) const
{ {
FATAL_ERROR("Deprecated function (?)"); FATAL_ERROR("Deprecated function");
return "";
} }
void PlayerSAO::step(float dtime, bool send_recommended) void PlayerSAO::step(float dtime, bool send_recommended)

@ -102,7 +102,7 @@ public:
const std::string &data); const std::string &data);
void step(float dtime, bool send_recommended); void step(float dtime, bool send_recommended);
std::string getClientInitializationData(u16 protocol_version); std::string getClientInitializationData(u16 protocol_version);
std::string getStaticData() const; void getStaticData(std::string *result) const;
int punch(v3f dir, int punch(v3f dir,
const ToolCapabilities *toolcap=NULL, const ToolCapabilities *toolcap=NULL,
ServerActiveObject *puncher=NULL, ServerActiveObject *puncher=NULL,
@ -199,7 +199,7 @@ public:
void removingFromEnvironment(); void removingFromEnvironment();
bool isStaticAllowed() const { return false; } bool isStaticAllowed() const { return false; }
std::string getClientInitializationData(u16 protocol_version); std::string getClientInitializationData(u16 protocol_version);
std::string getStaticData() const; void getStaticData(std::string *result) const;
void step(float dtime, bool send_recommended); void step(float dtime, bool send_recommended);
void setBasePosition(const v3f &position); void setBasePosition(const v3f &position);
void setPos(const v3f &pos); void setPos(const v3f &pos);

@ -1694,7 +1694,8 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
{ {
// Add static object to active static list of the block // Add static object to active static list of the block
v3f objectpos = object->getBasePosition(); v3f objectpos = object->getBasePosition();
std::string staticdata = object->getStaticData(); std::string staticdata = "";
object->getStaticData(&staticdata);
StaticObject s_obj(object->getType(), objectpos, staticdata); StaticObject s_obj(object->getType(), objectpos, staticdata);
// Add to the block where the object is located in // Add to the block where the object is located in
v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
@ -1980,7 +1981,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
<<std::endl; <<std::endl;
continue; continue;
} }
std::string staticdata_new = obj->getStaticData(); std::string staticdata_new = "";
obj->getStaticData(&staticdata_new);
StaticObject s_obj(obj->getType(), objectpos, staticdata_new); StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
block->m_static_objects.insert(id, s_obj); block->m_static_objects.insert(id, s_obj);
obj->m_static_block = blockpos_o; obj->m_static_block = blockpos_o;
@ -2020,7 +2022,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
if(obj->isStaticAllowed()) if(obj->isStaticAllowed())
{ {
// Create new static object // 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); StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
bool stays_in_same_block = false; bool stays_in_same_block = false;

@ -119,10 +119,10 @@ public:
when it is created (converted from static to active - actually when it is created (converted from static to active - actually
the data is the static form) the data is the static form)
*/ */
virtual std::string getStaticData() virtual void getStaticData(std::string *result)
{ {
assert(isStaticAllowed()); assert(isStaticAllowed());
return ""; *result = "";
} }
/* /*
Return false in here to never save and instead remove object Return false in here to never save and instead remove object