Fix various variables passed by copy instead of const ref (#5610)

Pointed by cppcheck
This commit is contained in:
Loïc Blot 2017-04-19 00:36:30 +02:00 committed by GitHub
parent 5f2af7c4e8
commit cf37a55690
14 changed files with 31 additions and 29 deletions

@ -43,7 +43,7 @@ enum ActiveObjectType {
struct ActiveObjectMessage struct ActiveObjectMessage
{ {
ActiveObjectMessage(u16 id_, bool reliable_=true, std::string data_=""): ActiveObjectMessage(u16 id_, bool reliable_=true, const std::string &data_ = "") :
id(id_), id(id_),
reliable(reliable_), reliable(reliable_),
datastring(data_) datastring(data_)

@ -57,7 +57,7 @@ extern gui::IGUIEnvironment* guienv;
Client::Client( Client::Client(
IrrlichtDevice *device, IrrlichtDevice *device,
const char *playername, const char *playername,
std::string password, const std::string &password,
MapDrawControl &control, MapDrawControl &control,
IWritableTextureSource *tsrc, IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc, IWritableShaderSource *shsrc,

@ -245,7 +245,7 @@ public:
Client( Client(
IrrlichtDevice *device, IrrlichtDevice *device,
const char *playername, const char *playername,
std::string password, const std::string &password,
MapDrawControl &control, MapDrawControl &control,
IWritableTextureSource *tsrc, IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc, IWritableShaderSource *shsrc,

@ -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(); ITextureSource *tsrc = m_client->tsrc();

@ -200,7 +200,7 @@ public:
void updateTexturePos(); void updateTexturePos();
void updateTextures(const std::string mod); void updateTextures(const std::string &mod);
void updateAnimation(); void updateAnimation();

@ -30,7 +30,7 @@ public:
/* /*
'dir' is the file cache directory to use. '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 update(const std::string &name, const std::string &data);
bool load(const std::string &name, std::ostream &os); bool load(const std::string &name, std::ostream &os);

@ -79,14 +79,15 @@ extern Profiler *g_profiler;
Text input system Text input system
*/ */
struct TextDestNodeMetadata : public TextDest { struct TextDestNodeMetadata : public TextDest
{
TextDestNodeMetadata(v3s16 p, Client *client) TextDestNodeMetadata(v3s16 p, Client *client)
{ {
m_p = p; m_p = p;
m_client = client; m_client = client;
} }
// This is deprecated I guess? -celeron55 // This is deprecated I guess? -celeron55
void gotText(std::wstring text) void gotText(const std::wstring &text)
{ {
std::string ntext = wide_to_utf8(text); std::string ntext = wide_to_utf8(text);
infostream << "Submitting 'text' field of node at (" << m_p.X << "," infostream << "Submitting 'text' field of node at (" << m_p.X << ","
@ -104,13 +105,14 @@ struct TextDestNodeMetadata : public TextDest {
Client *m_client; Client *m_client;
}; };
struct TextDestPlayerInventory : public TextDest { struct TextDestPlayerInventory : public TextDest
{
TextDestPlayerInventory(Client *client) TextDestPlayerInventory(Client *client)
{ {
m_client = client; m_client = client;
m_formname = ""; m_formname = "";
} }
TextDestPlayerInventory(Client *client, std::string formname) TextDestPlayerInventory(Client *client, const std::string &formname)
{ {
m_client = client; m_client = client;
m_formname = formname; m_formname = formname;
@ -131,13 +133,13 @@ struct LocalFormspecHandler : public TextDest
m_formname = formname; m_formname = formname;
} }
LocalFormspecHandler(std::string formname, Client *client): LocalFormspecHandler(const std::string &formname, Client *client):
m_client(client) m_client(client)
{ {
m_formname = formname; m_formname = formname;
} }
void gotText(std::wstring message) void gotText(const std::wstring &message)
{ {
errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl; errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
} }
@ -1190,7 +1192,7 @@ protected:
u16 port, u16 port,
const SubgameSpec &gamespec); const SubgameSpec &gamespec);
bool initSound(); bool initSound();
bool createSingleplayerServer(const std::string map_dir, bool createSingleplayerServer(const std::string &map_dir,
const SubgameSpec &gamespec, u16 port, std::string *address); const SubgameSpec &gamespec, u16 port, std::string *address);
// Client creation // Client creation
@ -1780,7 +1782,7 @@ bool Game::initSound()
return true; 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) const SubgameSpec &gamespec, u16 port, std::string *address)
{ {
showOverlayMessage(wgettext("Creating server..."), 0, 5); showOverlayMessage(wgettext("Creating server..."), 0, 5);

@ -1226,7 +1226,8 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) {
/* /*
ServerMap ServerMap
*/ */
ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge): ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef,
EmergeManager *emerge):
Map(dout_server, gamedef), Map(dout_server, gamedef),
settings_mgr(g_settings, savedir + DIR_DELIM + "map_meta.txt"), settings_mgr(g_settings, savedir + DIR_DELIM + "map_meta.txt"),
m_emerge(emerge), 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; unsigned int x = 0, y = 0;
int r; int r;
@ -1966,7 +1967,7 @@ v2s16 ServerMap::getSectorPos(std::string dirname)
return pos; 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); v2s16 p2d = getSectorPos(sectordir);

@ -360,7 +360,7 @@ public:
/* /*
savedir: directory to which map data should be saved 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(); ~ServerMap();
s32 mapType() const s32 mapType() const
@ -422,16 +422,14 @@ public:
// returns something like "map/sectors/xxxxxxxx" // returns something like "map/sectors/xxxxxxxx"
std::string getSectorDir(v2s16 pos, int layout = 2); std::string getSectorDir(v2s16 pos, int layout = 2);
// dirname: final directory name // dirname: final directory name
v2s16 getSectorPos(std::string dirname); v2s16 getSectorPos(const std::string &dirname);
v3s16 getBlockPos(std::string sectordir, std::string blockfile); v3s16 getBlockPos(const std::string &sectordir, const std::string &blockfile);
static std::string getBlockFilename(v3s16 p); static std::string getBlockFilename(v3s16 p);
/* /*
Database functions Database functions
*/ */
static Database *createDatabase(const std::string &name, const std::string &savedir, Settings &conf); 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 // Returns true if the database file does not exist
bool loadFromFolders(); bool loadFromFolders();

@ -347,7 +347,7 @@ ClientModConfiguration::ClientModConfiguration(const std::string &path):
#endif #endif
#if USE_CURL #if USE_CURL
Json::Value getModstoreUrl(std::string url) Json::Value getModstoreUrl(const std::string &url)
{ {
std::vector<std::string> extra_headers; std::vector<std::string> extra_headers;

@ -146,9 +146,10 @@ public:
#endif #endif
#if USE_CURL #if USE_CURL
Json::Value getModstoreUrl(std::string url); Json::Value getModstoreUrl(const std::string &url);
#else #else
inline Json::Value getModstoreUrl(std::string url) { inline Json::Value getModstoreUrl(const std::string &url)
{
return Json::Value(); return Json::Value();
} }
#endif #endif

@ -340,7 +340,7 @@ IWritableShaderSource* createShaderSource(IrrlichtDevice *device)
/* /*
Generate shader given the shader name. Generate shader given the shader name.
*/ */
ShaderInfo generate_shader(std::string name, ShaderInfo generate_shader(const std::string &name,
u8 material_type, u8 drawtype, u8 material_type, u8 drawtype,
IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks, IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
const std::vector<IShaderConstantSetterFactory*> &setter_factories, 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, IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
const std::vector<IShaderConstantSetterFactory*> &setter_factories, const std::vector<IShaderConstantSetterFactory*> &setter_factories,
SourceShaderCache *sourcecache) SourceShaderCache *sourcecache)

@ -113,7 +113,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0,
// L-System tree LUA spawner // L-System tree LUA spawner
treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0, treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
INodeDefManager *ndef, TreeDef tree_definition) INodeDefManager *ndef, const TreeDef &tree_definition)
{ {
ServerMap *map = &env->getServerMap(); ServerMap *map = &env->getServerMap();
std::map<v3s16, MapBlock*> modified_blocks; std::map<v3s16, MapBlock*> modified_blocks;

@ -73,7 +73,7 @@ namespace treegen {
TreeDef tree_definition); TreeDef tree_definition);
// Spawn L-systems tree from LUA // Spawn L-systems tree from LUA
treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef,
TreeDef tree_definition); const TreeDef &tree_definition);
// L-System tree gen helper functions // L-System tree gen helper functions
void tree_node_placement(MMVManip &vmanip, v3f p0, void tree_node_placement(MMVManip &vmanip, v3f p0,