Optimize SAO getStaticData by using std::string pointer instead of return copy
authorLoic Blot <loic.blot@unix-experience.fr>
Wed, 11 Jan 2017 21:48:14 +0000 (22:48 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Fri, 13 Jan 2017 20:56:24 +0000 (21:56 +0100)
Signed-off-by: Loic Blot <loic.blot@unix-experience.fr>
src/content_sao.cpp
src/content_sao.h
src/serverenvironment.cpp
src/serverobject.h

index 852e2d788600baad300625579573d987e4256303..bf8282af46aa1ec86dcb02fa15a1357af15486d7 100644 (file)
@@ -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<<FUNCTION_NAME<<std::endl;
        std::ostringstream os(std::ios::binary);
@@ -543,7 +543,7 @@ std::string LuaEntitySAO::getStaticData() const
        writeV3F1000(os, m_velocity);
        // yaw
        writeF1000(os, m_yaw);
-       return os.str();
+       *result = os.str();
 }
 
 int LuaEntitySAO::punch(v3f dir,
@@ -918,10 +918,9 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
        return os.str();
 }
 
-std::string PlayerSAO::getStaticData() const
+void PlayerSAO::getStaticData(std::string *result) const
 {
-       FATAL_ERROR("Deprecated function (?)");
-       return "";
+       FATAL_ERROR("Deprecated function");
 }
 
 void PlayerSAO::step(float dtime, bool send_recommended)
index 4d6cf4dcfe3fa42a2446d383e70319bda308fb93..4abe932501179015718837ad9f03efff42befa7a 100644 (file)
@@ -102,7 +102,7 @@ public:
                        const std::string &data);
        void step(float dtime, bool send_recommended);
        std::string getClientInitializationData(u16 protocol_version);
-       std::string getStaticData() const;
+       void getStaticData(std::string *result) const;
        int punch(v3f dir,
                        const ToolCapabilities *toolcap=NULL,
                        ServerActiveObject *puncher=NULL,
@@ -199,7 +199,7 @@ public:
        void removingFromEnvironment();
        bool isStaticAllowed() const { return false; }
        std::string getClientInitializationData(u16 protocol_version);
-       std::string getStaticData() const;
+       void getStaticData(std::string *result) const;
        void step(float dtime, bool send_recommended);
        void setBasePosition(const v3f &position);
        void setPos(const v3f &pos);
index e1962bcff9ac5e54e9078c41a55170ad322418b0..d3b85a4301f8e7cea82f8038460a31bd4d2ccbcd 100644 (file)
@@ -1694,7 +1694,8 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
        {
                // Add static object to active static list of the block
                v3f objectpos = object->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)
                                        <<std::endl;
                                continue;
                        }
-                       std::string staticdata_new = obj->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;
index 9e8b5a779f6b798bf48cc8ed4592c512bfc8ddb3..26c8b062d61f63a2e28245acc2a5f89357f810ca 100644 (file)
@@ -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