Fix various variables passed by copy instead of const ref (#5610)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Tue, 18 Apr 2017 22:36:30 +0000 (00:36 +0200)
committerGitHub <noreply@github.com>
Tue, 18 Apr 2017 22:36:30 +0000 (00:36 +0200)
Pointed by cppcheck

14 files changed:
src/activeobject.h
src/client.cpp
src/client.h
src/content_cao.cpp
src/content_cao.h
src/filecache.h
src/game.cpp
src/map.cpp
src/map.h
src/mods.cpp
src/mods.h
src/shader.cpp
src/treegen.cpp
src/treegen.h

index fe6c085141df192cccca5b3f37f8c193a505a1e4..71b9df5147b545a7f3eb237eda5c987349134757 100644 (file)
@@ -43,7 +43,7 @@ enum ActiveObjectType {
 
 struct ActiveObjectMessage
 {
-       ActiveObjectMessage(u16 id_, bool reliable_=true, std::string data_=""):
+       ActiveObjectMessage(u16 id_, bool reliable_=true, const std::string &data_ = "") :
                id(id_),
                reliable(reliable_),
                datastring(data_)
index 7b962cd94acb9d3ffc347f5d3a0a8e64351426bf..3cea4fbf40079559197bc7cb0b09e12cf1cd8c61 100644 (file)
@@ -57,7 +57,7 @@ extern gui::IGUIEnvironment* guienv;
 Client::Client(
                IrrlichtDevice *device,
                const char *playername,
-               std::string password,
+               const std::string &password,
                MapDrawControl &control,
                IWritableTextureSource *tsrc,
                IWritableShaderSource *shsrc,
index e7fcb597df936c61428f45d87a0ca48f87ce3e06..c55d7bcd5ec5326bcf5ed3f2f70fcd9f36acd6c8 100644 (file)
@@ -245,7 +245,7 @@ public:
        Client(
                        IrrlichtDevice *device,
                        const char *playername,
-                       std::string password,
+                       const std::string &password,
                        MapDrawControl &control,
                        IWritableTextureSource *tsrc,
                        IWritableShaderSource *shsrc,
index ac283da88c1c3bb88a8df2ba259a2854c27af45c..3aa3bad97094c95e883d73a440ca324fec6b22a3 100644 (file)
@@ -1313,7 +1313,7 @@ void GenericCAO::updateTexturePos()
        }
 }
 
-void GenericCAO::updateTextures(const std::string mod)
+void GenericCAO::updateTextures(const std::string &mod)
 {
        ITextureSource *tsrc = m_client->tsrc();
 
index f30e90e21049f2359d13a8c34c27461e18326299..a0601d692be8f0631ccf23eaf94975ed65684637 100644 (file)
@@ -200,7 +200,7 @@ public:
 
        void updateTexturePos();
 
-       void updateTextures(const std::string mod);
+       void updateTextures(const std::string &mod);
 
        void updateAnimation();
 
index f390f71b724977afd1fe8b01c91c13f4fc750aae..627ab45edc147680132e9970d57df69e8955ff1e 100644 (file)
@@ -30,7 +30,7 @@ public:
        /*
                'dir' is the file cache directory to use.
        */
-       FileCache(std::string dir) : m_dir(dir) {}
+       FileCache(const std::string &dir) : m_dir(dir) {}
 
        bool update(const std::string &name, const std::string &data);
        bool load(const std::string &name, std::ostream &os);
index f584a58ef218a04d6dac5607de23bda0bbb3760d..198baeca3922df651fe5f822d1467927e3282e54 100644 (file)
@@ -79,14 +79,15 @@ extern Profiler *g_profiler;
        Text input system
 */
 
-struct TextDestNodeMetadata : public TextDest {
+struct TextDestNodeMetadata : public TextDest
+{
        TextDestNodeMetadata(v3s16 p, Client *client)
        {
                m_p = p;
                m_client = client;
        }
        // This is deprecated I guess? -celeron55
-       void gotText(std::wstring text)
+       void gotText(const std::wstring &text)
        {
                std::string ntext = wide_to_utf8(text);
                infostream << "Submitting 'text' field of node at (" << m_p.X << ","
@@ -104,13 +105,14 @@ struct TextDestNodeMetadata : public TextDest {
        Client *m_client;
 };
 
-struct TextDestPlayerInventory : public TextDest {
+struct TextDestPlayerInventory : public TextDest
+{
        TextDestPlayerInventory(Client *client)
        {
                m_client = client;
                m_formname = "";
        }
-       TextDestPlayerInventory(Client *client, std::string formname)
+       TextDestPlayerInventory(Client *client, const std::string &formname)
        {
                m_client = client;
                m_formname = formname;
@@ -131,13 +133,13 @@ struct LocalFormspecHandler : public TextDest
                m_formname = formname;
        }
 
-       LocalFormspecHandler(std::string formname, Client *client):
+       LocalFormspecHandler(const std::string &formname, Client *client):
                m_client(client)
        {
                m_formname = formname;
        }
 
-       void gotText(std::wstring message)
+       void gotText(const std::wstring &message)
        {
                errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
        }
@@ -1190,7 +1192,7 @@ protected:
                        u16 port,
                        const SubgameSpec &gamespec);
        bool initSound();
-       bool createSingleplayerServer(const std::string map_dir,
+       bool createSingleplayerServer(const std::string &map_dir,
                        const SubgameSpec &gamespec, u16 port, std::string *address);
 
        // Client creation
@@ -1780,7 +1782,7 @@ bool Game::initSound()
        return true;
 }
 
-bool Game::createSingleplayerServer(const std::string map_dir,
+bool Game::createSingleplayerServer(const std::string &map_dir,
                const SubgameSpec &gamespec, u16 port, std::string *address)
 {
        showOverlayMessage(wgettext("Creating server..."), 0, 5);
index b690ea3b3c60649fbad10e1ae3ac44cbec7ebece..3da96e77b4ab9404e59603d00ad019d6080ab42f 100644 (file)
@@ -1226,7 +1226,8 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) {
 /*
        ServerMap
 */
-ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge):
+ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef,
+               EmergeManager *emerge):
        Map(dout_server, gamedef),
        settings_mgr(g_settings, savedir + DIR_DELIM + "map_meta.txt"),
        m_emerge(emerge),
@@ -1936,7 +1937,7 @@ std::string ServerMap::getSectorDir(v2s16 pos, int layout)
        }
 }
 
-v2s16 ServerMap::getSectorPos(std::string dirname)
+v2s16 ServerMap::getSectorPos(const std::string &dirname)
 {
        unsigned int x = 0, y = 0;
        int r;
@@ -1966,7 +1967,7 @@ v2s16 ServerMap::getSectorPos(std::string dirname)
        return pos;
 }
 
-v3s16 ServerMap::getBlockPos(std::string sectordir, std::string blockfile)
+v3s16 ServerMap::getBlockPos(const std::string &sectordir, const std::string &blockfile)
 {
        v2s16 p2d = getSectorPos(sectordir);
 
index ea8dc76d1ba9a3634e7d38e09ad20eaf7c437481..90f97db8b43bfb52f898b0804511c30e18e4e510 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -360,7 +360,7 @@ public:
        /*
                savedir: directory to which map data should be saved
        */
-       ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge);
+       ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge);
        ~ServerMap();
 
        s32 mapType() const
@@ -422,16 +422,14 @@ public:
        // returns something like "map/sectors/xxxxxxxx"
        std::string getSectorDir(v2s16 pos, int layout = 2);
        // dirname: final directory name
-       v2s16 getSectorPos(std::string dirname);
-       v3s16 getBlockPos(std::string sectordir, std::string blockfile);
+       v2s16 getSectorPos(const std::string &dirname);
+       v3s16 getBlockPos(const std::string &sectordir, const std::string &blockfile);
        static std::string getBlockFilename(v3s16 p);
 
        /*
                Database functions
        */
        static Database *createDatabase(const std::string &name, const std::string &savedir, Settings &conf);
-       // Verify we can read/write to the database
-       void verifyDatabase();
 
        // Returns true if the database file does not exist
        bool loadFromFolders();
index 5a7dc6dcaf7c29a33a8ecb6b5c6e965370aedad7..6fce8e93d1d45140a0cad4379ff9089be74d814c 100644 (file)
@@ -347,7 +347,7 @@ ClientModConfiguration::ClientModConfiguration(const std::string &path):
 #endif
 
 #if USE_CURL
-Json::Value getModstoreUrl(std::string url)
+Json::Value getModstoreUrl(const std::string &url)
 {
        std::vector<std::string> extra_headers;
 
index c9bd51d992f6e6b78478517050a876ca480316bf..1e62db54d41ceda2b3849eac5935448924f1ff42 100644 (file)
@@ -146,9 +146,10 @@ public:
 #endif
 
 #if USE_CURL
-Json::Value getModstoreUrl(std::string url);
+Json::Value getModstoreUrl(const std::string &url);
 #else
-inline Json::Value getModstoreUrl(std::string url) {
+inline Json::Value getModstoreUrl(const std::string &url)
+{
        return Json::Value();
 }
 #endif
index 79485025b30675169d4fc034aecf1b21c1f6cb50..66f32c9a1846bc6e6439f63829841bbc72306698 100644 (file)
@@ -340,7 +340,7 @@ IWritableShaderSource* createShaderSource(IrrlichtDevice *device)
 /*
        Generate shader given the shader name.
 */
-ShaderInfo generate_shader(std::string name,
+ShaderInfo generate_shader(const std::string &name,
                u8 material_type, u8 drawtype,
                IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
                const std::vector<IShaderConstantSetterFactory*> &setter_factories,
@@ -525,7 +525,7 @@ void ShaderSource::rebuildShaders()
 }
 
 
-ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
+ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype,
                IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
                const std::vector<IShaderConstantSetterFactory*> &setter_factories,
                SourceShaderCache *sourcecache)
index 505954e8e07545ca923457e30977c5ddb03dfb50..8bf9619a0eba836b9db3e708b6bbdab07321423e 100644 (file)
@@ -113,7 +113,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0,
 
 // L-System tree LUA spawner
 treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
-               INodeDefManager *ndef, TreeDef tree_definition)
+               INodeDefManager *ndef, const TreeDef &tree_definition)
 {
        ServerMap *map = &env->getServerMap();
        std::map<v3s16, MapBlock*> modified_blocks;
index 4e6f95e6766cf2f9909bd4d00b458e82e82d107e..8777c369cc4d4fe6b253aad0698b5f6a880a6f0d 100644 (file)
@@ -73,7 +73,7 @@ namespace treegen {
                TreeDef tree_definition);
        // Spawn L-systems tree from LUA
        treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef,
-               TreeDef tree_definition);
+               const TreeDef &tree_definition);
 
        // L-System tree gen helper functions
        void tree_node_placement(MMVManip &vmanip, v3f p0,