Skip to content

Commit cf37a55

Browse files
authoredApr 18, 2017
Fix various variables passed by copy instead of const ref (#5610)
Pointed by cppcheck
1 parent 5f2af7c commit cf37a55

14 files changed

+31
-29
lines changed
 

Diff for: ‎src/activeobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum ActiveObjectType {
4343

4444
struct ActiveObjectMessage
4545
{
46-
ActiveObjectMessage(u16 id_, bool reliable_=true, std::string data_=""):
46+
ActiveObjectMessage(u16 id_, bool reliable_=true, const std::string &data_ = "") :
4747
id(id_),
4848
reliable(reliable_),
4949
datastring(data_)

Diff for: ‎src/client.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern gui::IGUIEnvironment* guienv;
5757
Client::Client(
5858
IrrlichtDevice *device,
5959
const char *playername,
60-
std::string password,
60+
const std::string &password,
6161
MapDrawControl &control,
6262
IWritableTextureSource *tsrc,
6363
IWritableShaderSource *shsrc,

Diff for: ‎src/client.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
245245
Client(
246246
IrrlichtDevice *device,
247247
const char *playername,
248-
std::string password,
248+
const std::string &password,
249249
MapDrawControl &control,
250250
IWritableTextureSource *tsrc,
251251
IWritableShaderSource *shsrc,

Diff for: ‎src/content_cao.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ void GenericCAO::updateTexturePos()
13131313
}
13141314
}
13151315

1316-
void GenericCAO::updateTextures(const std::string mod)
1316+
void GenericCAO::updateTextures(const std::string &mod)
13171317
{
13181318
ITextureSource *tsrc = m_client->tsrc();
13191319

Diff for: ‎src/content_cao.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class GenericCAO : public ClientActiveObject
200200

201201
void updateTexturePos();
202202

203-
void updateTextures(const std::string mod);
203+
void updateTextures(const std::string &mod);
204204

205205
void updateAnimation();
206206

Diff for: ‎src/filecache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FileCache
3030
/*
3131
'dir' is the file cache directory to use.
3232
*/
33-
FileCache(std::string dir) : m_dir(dir) {}
33+
FileCache(const std::string &dir) : m_dir(dir) {}
3434

3535
bool update(const std::string &name, const std::string &data);
3636
bool load(const std::string &name, std::ostream &os);

Diff for: ‎src/game.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ extern Profiler *g_profiler;
7979
Text input system
8080
*/
8181

82-
struct TextDestNodeMetadata : public TextDest {
82+
struct TextDestNodeMetadata : public TextDest
83+
{
8384
TextDestNodeMetadata(v3s16 p, Client *client)
8485
{
8586
m_p = p;
8687
m_client = client;
8788
}
8889
// This is deprecated I guess? -celeron55
89-
void gotText(std::wstring text)
90+
void gotText(const std::wstring &text)
9091
{
9192
std::string ntext = wide_to_utf8(text);
9293
infostream << "Submitting 'text' field of node at (" << m_p.X << ","
@@ -104,13 +105,14 @@ struct TextDestNodeMetadata : public TextDest {
104105
Client *m_client;
105106
};
106107

107-
struct TextDestPlayerInventory : public TextDest {
108+
struct TextDestPlayerInventory : public TextDest
109+
{
108110
TextDestPlayerInventory(Client *client)
109111
{
110112
m_client = client;
111113
m_formname = "";
112114
}
113-
TextDestPlayerInventory(Client *client, std::string formname)
115+
TextDestPlayerInventory(Client *client, const std::string &formname)
114116
{
115117
m_client = client;
116118
m_formname = formname;
@@ -131,13 +133,13 @@ struct LocalFormspecHandler : public TextDest
131133
m_formname = formname;
132134
}
133135

134-
LocalFormspecHandler(std::string formname, Client *client):
136+
LocalFormspecHandler(const std::string &formname, Client *client):
135137
m_client(client)
136138
{
137139
m_formname = formname;
138140
}
139141

140-
void gotText(std::wstring message)
142+
void gotText(const std::wstring &message)
141143
{
142144
errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
143145
}
@@ -1190,7 +1192,7 @@ class Game {
11901192
u16 port,
11911193
const SubgameSpec &gamespec);
11921194
bool initSound();
1193-
bool createSingleplayerServer(const std::string map_dir,
1195+
bool createSingleplayerServer(const std::string &map_dir,
11941196
const SubgameSpec &gamespec, u16 port, std::string *address);
11951197

11961198
// Client creation
@@ -1780,7 +1782,7 @@ bool Game::initSound()
17801782
return true;
17811783
}
17821784

1783-
bool Game::createSingleplayerServer(const std::string map_dir,
1785+
bool Game::createSingleplayerServer(const std::string &map_dir,
17841786
const SubgameSpec &gamespec, u16 port, std::string *address)
17851787
{
17861788
showOverlayMessage(wgettext("Creating server..."), 0, 5);

Diff for: ‎src/map.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,8 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) {
12261226
/*
12271227
ServerMap
12281228
*/
1229-
ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge):
1229+
ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef,
1230+
EmergeManager *emerge):
12301231
Map(dout_server, gamedef),
12311232
settings_mgr(g_settings, savedir + DIR_DELIM + "map_meta.txt"),
12321233
m_emerge(emerge),
@@ -1936,7 +1937,7 @@ std::string ServerMap::getSectorDir(v2s16 pos, int layout)
19361937
}
19371938
}
19381939

1939-
v2s16 ServerMap::getSectorPos(std::string dirname)
1940+
v2s16 ServerMap::getSectorPos(const std::string &dirname)
19401941
{
19411942
unsigned int x = 0, y = 0;
19421943
int r;
@@ -1966,7 +1967,7 @@ v2s16 ServerMap::getSectorPos(std::string dirname)
19661967
return pos;
19671968
}
19681969

1969-
v3s16 ServerMap::getBlockPos(std::string sectordir, std::string blockfile)
1970+
v3s16 ServerMap::getBlockPos(const std::string &sectordir, const std::string &blockfile)
19701971
{
19711972
v2s16 p2d = getSectorPos(sectordir);
19721973

Diff for: ‎src/map.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class ServerMap : public Map
360360
/*
361361
savedir: directory to which map data should be saved
362362
*/
363-
ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge);
363+
ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge);
364364
~ServerMap();
365365

366366
s32 mapType() const
@@ -422,16 +422,14 @@ class ServerMap : public Map
422422
// returns something like "map/sectors/xxxxxxxx"
423423
std::string getSectorDir(v2s16 pos, int layout = 2);
424424
// dirname: final directory name
425-
v2s16 getSectorPos(std::string dirname);
426-
v3s16 getBlockPos(std::string sectordir, std::string blockfile);
425+
v2s16 getSectorPos(const std::string &dirname);
426+
v3s16 getBlockPos(const std::string &sectordir, const std::string &blockfile);
427427
static std::string getBlockFilename(v3s16 p);
428428

429429
/*
430430
Database functions
431431
*/
432432
static Database *createDatabase(const std::string &name, const std::string &savedir, Settings &conf);
433-
// Verify we can read/write to the database
434-
void verifyDatabase();
435433

436434
// Returns true if the database file does not exist
437435
bool loadFromFolders();

Diff for: ‎src/mods.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ ClientModConfiguration::ClientModConfiguration(const std::string &path):
347347
#endif
348348

349349
#if USE_CURL
350-
Json::Value getModstoreUrl(std::string url)
350+
Json::Value getModstoreUrl(const std::string &url)
351351
{
352352
std::vector<std::string> extra_headers;
353353

Diff for: ‎src/mods.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ class ClientModConfiguration: public ModConfiguration
146146
#endif
147147

148148
#if USE_CURL
149-
Json::Value getModstoreUrl(std::string url);
149+
Json::Value getModstoreUrl(const std::string &url);
150150
#else
151-
inline Json::Value getModstoreUrl(std::string url) {
151+
inline Json::Value getModstoreUrl(const std::string &url)
152+
{
152153
return Json::Value();
153154
}
154155
#endif

Diff for: ‎src/shader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ IWritableShaderSource* createShaderSource(IrrlichtDevice *device)
340340
/*
341341
Generate shader given the shader name.
342342
*/
343-
ShaderInfo generate_shader(std::string name,
343+
ShaderInfo generate_shader(const std::string &name,
344344
u8 material_type, u8 drawtype,
345345
IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
346346
const std::vector<IShaderConstantSetterFactory*> &setter_factories,
@@ -525,7 +525,7 @@ void ShaderSource::rebuildShaders()
525525
}
526526

527527

528-
ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
528+
ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype,
529529
IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
530530
const std::vector<IShaderConstantSetterFactory*> &setter_factories,
531531
SourceShaderCache *sourcecache)

Diff for: ‎src/treegen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0,
113113

114114
// L-System tree LUA spawner
115115
treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
116-
INodeDefManager *ndef, TreeDef tree_definition)
116+
INodeDefManager *ndef, const TreeDef &tree_definition)
117117
{
118118
ServerMap *map = &env->getServerMap();
119119
std::map<v3s16, MapBlock*> modified_blocks;

Diff for: ‎src/treegen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace treegen {
7373
TreeDef tree_definition);
7474
// Spawn L-systems tree from LUA
7575
treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef,
76-
TreeDef tree_definition);
76+
const TreeDef &tree_definition);
7777

7878
// L-System tree gen helper functions
7979
void tree_node_placement(MMVManip &vmanip, v3f p0,

0 commit comments

Comments
 (0)
Please sign in to comment.