← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-986611-cppcheck-pass-by-reference into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-986611-cppcheck-pass-by-reference into lp:widelands.

Commit message:
Pass function arguments per (const) reference where possible.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #986611 in widelands: "Issues reported by cppcheck"
  https://bugs.launchpad.net/widelands/+bug/986611

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-986611-cppcheck-pass-by-reference/+merge/326257

This cleanup should gain us a bit of performance. Changes are pretty trivial (argument -> (const) argument&)
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-986611-cppcheck-pass-by-reference into lp:widelands.
=== modified file 'src/base/i18n.cc'
--- src/base/i18n.cc	2017-01-25 18:55:59 +0000
+++ src/base/i18n.cc	2017-06-24 11:37:18 +0000
@@ -76,7 +76,7 @@
 /**
  * Set the localedir. This should usually only be done once
  */
-void set_localedir(std::string dname) {
+void set_localedir(const std::string& dname) {
 	localedir = dname;
 }
 
@@ -157,7 +157,7 @@
  * Set the locale to the given string.
  * Code inspired by wesnoth.org
  */
-void set_locale(std::string name) {
+void set_locale(const std::string& name) {
 	const std::map<std::string, std::string> kAlternatives = {
 	   {"ar", "ar,ar_AR,ar_AE,ar_BH,ar_DZ,ar_EG,ar_IN,ar_IQ,ar_JO,ar_KW,ar_LB,ar_LY,ar_MA,ar_OM,ar_"
 	          "QA,ar_SA,ar_SD,ar_SY,ar_TN,ar_YE"},

=== modified file 'src/base/i18n.h'
--- src/base/i18n.h	2017-01-25 18:55:59 +0000
+++ src/base/i18n.h	2017-06-24 11:37:18 +0000
@@ -52,10 +52,10 @@
 };
 
 void init_locale();
-void set_locale(std::string);
+void set_locale(const std::string&);
 const std::string& get_locale();
 
-void set_localedir(std::string);
+void set_localedir(const std::string&);
 const std::string& get_localedir();
 
 // Localize a list of 'items'. The last 2 items are concatenated with "and" or

=== modified file 'src/editor/tools/tool_action.h'
--- src/editor/tools/tool_action.h	2017-01-25 18:55:59 +0000
+++ src/editor/tools/tool_action.h	2017-06-24 11:37:18 +0000
@@ -46,7 +46,7 @@
 	                 Widelands::Map& m,
 	                 Widelands::NodeAndTriangle<> c,
 	                 EditorInteractive& p,
-	                 EditorActionArgs nargs)
+	                 const EditorActionArgs& nargs)
 	   : tool(t), i(ind), map(m), center(c), parent(p) {
 		args = new EditorActionArgs(parent);
 		*args = nargs;

=== modified file 'src/graphic/text/rt_errors.h'
--- src/graphic/text/rt_errors.h	2017-01-25 18:55:59 +0000
+++ src/graphic/text/rt_errors.h	2017-06-24 11:37:18 +0000
@@ -28,7 +28,7 @@
 
 class Exception : public std::exception {
 public:
-	Exception(std::string msg) : std::exception(), msg_(msg) {
+	explicit Exception(const std::string& msg) : std::exception(), msg_(msg) {
 	}
 	const char* what() const noexcept override {
 		return msg_.c_str();
@@ -41,7 +41,7 @@
 #define DEF_ERR(Name)                                                                              \
 	class Name : public Exception {                                                                 \
 	public:                                                                                         \
-		Name(std::string msg) : Exception(msg) {                                                     \
+		explicit Name(const std::string& msg) : Exception(msg) {                                                     \
 		}                                                                                            \
 	};
 

=== modified file 'src/graphic/text/rt_errors_impl.h'
--- src/graphic/text/rt_errors_impl.h	2017-01-25 18:55:59 +0000
+++ src/graphic/text/rt_errors_impl.h	2017-06-24 11:37:18 +0000
@@ -28,7 +28,7 @@
 
 struct SyntaxErrorImpl : public SyntaxError {
 	SyntaxErrorImpl(
-	   size_t line, size_t col, std::string expected, std::string got, std::string next_chars)
+	   size_t line, size_t col, const std::string& expected, const std::string& got, const std::string& next_chars)
 	   : SyntaxError(
 	        (boost::format(
 	            "Syntax error at %1%:%2%: expected %3%, got '%4%'. String continues with: '%5%'") %

=== modified file 'src/graphic/text/rt_parse.h'
--- src/graphic/text/rt_parse.h	2017-01-25 18:55:59 +0000
+++ src/graphic/text/rt_parse.h	2017-06-24 11:37:18 +0000
@@ -104,7 +104,7 @@
 	}
 	Child(Tag* t) : tag(t) {
 	}
-	Child(std::string t) : tag(nullptr), text(t) {
+	Child(const std::string& t) : tag(nullptr), text(t) {
 	}
 	~Child() {
 		if (tag)

=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc	2017-06-01 08:52:15 +0000
+++ src/graphic/text/rt_render.cc	2017-06-24 11:37:18 +0000
@@ -969,7 +969,7 @@
 public:
 	TagHandler(Tag& tag,
 	           FontCache& fc,
-	           NodeStyle ns,
+	           NodeStyle& ns,
 	           ImageCache* image_cache,
 	           RendererStyle& renderer_style,
 	           const UI::FontSets& fontsets)
@@ -1100,7 +1100,7 @@
 public:
 	FontTagHandler(Tag& tag,
 	               FontCache& fc,
-	               NodeStyle ns,
+	               NodeStyle& ns,
 	               ImageCache* image_cache,
 	               RendererStyle& init_renderer_style,
 	               const UI::FontSets& fontsets)
@@ -1132,7 +1132,7 @@
 public:
 	PTagHandler(Tag& tag,
 	            FontCache& fc,
-	            NodeStyle ns,
+	            NodeStyle& ns,
 	            ImageCache* image_cache,
 	            RendererStyle& init_renderer_style,
 	            const UI::FontSets& fontsets)
@@ -1186,7 +1186,7 @@
 public:
 	ImgTagHandler(Tag& tag,
 	              FontCache& fc,
-	              NodeStyle ns,
+	              NodeStyle& ns,
 	              ImageCache* image_cache,
 	              RendererStyle& init_renderer_style,
 	              const UI::FontSets& fontsets)
@@ -1231,7 +1231,7 @@
 public:
 	VspaceTagHandler(Tag& tag,
 	                 FontCache& fc,
-	                 NodeStyle ns,
+	                 NodeStyle& ns,
 	                 ImageCache* image_cache,
 	                 RendererStyle& init_renderer_style,
 	                 const UI::FontSets& fontsets)
@@ -1256,7 +1256,7 @@
 public:
 	HspaceTagHandler(Tag& tag,
 	                 FontCache& fc,
-	                 NodeStyle ns,
+	                 NodeStyle& ns,
 	                 ImageCache* image_cache,
 	                 RendererStyle& init_renderer_style,
 	                 const UI::FontSets& fontsets)
@@ -1317,7 +1317,7 @@
 public:
 	BrTagHandler(Tag& tag,
 	             FontCache& fc,
-	             NodeStyle ns,
+	             NodeStyle& ns,
 	             ImageCache* image_cache,
 	             RendererStyle& init_renderer_style,
 	             const UI::FontSets& fontsets)
@@ -1333,7 +1333,7 @@
 public:
 	DivTagHandler(Tag& tag,
 	              FontCache& fc,
-	              NodeStyle ns,
+	              NodeStyle& ns,
 	              ImageCache* image_cache,
 	              RendererStyle& init_renderer_style,
 	              const UI::FontSets& fontsets,
@@ -1503,7 +1503,7 @@
 public:
 	RTTagHandler(Tag& tag,
 	             FontCache& fc,
-	             NodeStyle ns,
+	             NodeStyle& ns,
 	             ImageCache* image_cache,
 	             RendererStyle& init_renderer_style,
 	             const UI::FontSets& fontsets,

=== modified file 'src/graphic/text/textstream.cc'
--- src/graphic/text/textstream.cc	2017-05-31 21:27:07 +0000
+++ src/graphic/text/textstream.cc	2017-06-24 11:37:18 +0000
@@ -29,7 +29,7 @@
 namespace RT {
 
 struct EndOfTextImpl : public EndOfText {
-	EndOfTextImpl(size_t pos, std::string text)
+	EndOfTextImpl(size_t pos, const std::string& text)
 	   : EndOfText(
 	        (format("Unexpected End of Text, starting at %1%. Text is: '%2%'") % pos % text).str()) {
 	}
@@ -133,7 +133,7 @@
 /*
  * Parse till any of the chars is found or the end of the string has been hit.
  */
-std::string TextStream::till_any_or_end(std::string chars) {
+std::string TextStream::till_any_or_end(const std::string& chars) {
 	std::string rv;
 	try {
 		rv = till_any(chars);

=== modified file 'src/graphic/text/textstream.h'
--- src/graphic/text/textstream.h	2017-01-25 18:55:59 +0000
+++ src/graphic/text/textstream.h	2017-06-24 11:37:18 +0000
@@ -28,7 +28,7 @@
 
 class TextStream {
 public:
-	TextStream(std::string text) : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {
+	TextStream(const std::string& text) : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {
 	}
 
 	size_t line() const {
@@ -45,7 +45,7 @@
 	void expect(std::string, bool = true);
 
 	std::string till_any(std::string);
-	std::string till_any_or_end(std::string);
+	std::string till_any_or_end(const std::string&);
 	std::string parse_string();
 
 	void skip(size_t d) {

=== modified file 'src/logic/map_objects/map_object.h'
--- src/logic/map_objects/map_object.h	2017-05-20 22:42:49 +0000
+++ src/logic/map_objects/map_object.h	2017-06-24 11:37:18 +0000
@@ -242,7 +242,7 @@
 	};
 
 	struct LogSink {
-		virtual void log(std::string str) = 0;
+		virtual void log(const std::string& str) = 0;
 		virtual ~LogSink() {
 		}
 	};

=== modified file 'src/logic/map_objects/tribes/tribe_basic_info.h'
--- src/logic/map_objects/tribes/tribe_basic_info.h	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/tribe_basic_info.h	2017-06-24 11:37:18 +0000
@@ -34,7 +34,7 @@
 
 	/// Script path and localized name for a starting condition
 	struct Initialization {
-		Initialization(std::string init_script, std::string init_descname, std::string init_tooltip)
+		Initialization(const std::string& init_script, const std::string& init_descname, const std::string& init_tooltip)
 		   : script(init_script), descname(init_descname), tooltip(init_tooltip) {
 		}
 		std::string script;

=== modified file 'src/network/gamehost.cc'
--- src/network/gamehost.cc	2017-06-23 08:33:03 +0000
+++ src/network/gamehost.cc	2017-06-24 11:37:18 +0000
@@ -909,7 +909,7 @@
  *   -   -1 if no client was found
  *   -   -2 if the host is the client (has no client number)
  */
-int32_t GameHost::check_client(std::string name) {
+int32_t GameHost::check_client(const std::string& name) {
 	// Check if the client is the host him-/herself
 	if (d->localplayername == name) {
 		return -2;
@@ -939,7 +939,7 @@
 * If the host sends a chat message with formation /kick <name> <reason>
 * This function will handle this command and try to kick the user.
 */
-void GameHost::kick_user(uint32_t client, std::string reason) {
+void GameHost::kick_user(uint32_t client, const std::string& reason) {
 	disconnect_client(client, "KICKED", true, reason);
 }
 

=== modified file 'src/network/gamehost.h'
--- src/network/gamehost.h	2017-06-05 07:33:18 +0000
+++ src/network/gamehost.h	2017-06-24 11:37:18 +0000
@@ -87,8 +87,8 @@
 	void send(ChatMessage msg);
 
 	//  Host command related stuff
-	int32_t check_client(std::string name);
-	void kick_user(uint32_t, std::string);
+	int32_t check_client(const std::string& name);
+	void kick_user(uint32_t, const std::string&);
 	void split_command_array(const std::string& cmdarray,
 	                         std::string& cmd,
 	                         std::string& arg1,

=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc	2017-06-04 16:01:13 +0000
+++ src/network/internet_gaming.cc	2017-06-24 11:37:18 +0000
@@ -803,10 +803,10 @@
 }
 
 /// formates a chat message and adds it to the list of chat messages
-void InternetGaming::format_and_add_chat(std::string from,
-                                         std::string to,
+void InternetGaming::format_and_add_chat(const std::string& from,
+                                         const std::string& to,
                                          bool system,
-                                         std::string msg) {
+                                         const std::string& msg) {
 	ChatMessage c;
 	if (!system && from.empty()) {
 		std::string unkown_string = (boost::format("<%s>") % _("unknown")).str();

=== modified file 'src/network/internet_gaming.h'
--- src/network/internet_gaming.h	2017-06-03 05:27:36 +0000
+++ src/network/internet_gaming.h	2017-06-24 11:37:18 +0000
@@ -153,7 +153,7 @@
 	bool str2bool(std::string);
 	std::string bool2str(bool);
 
-	void format_and_add_chat(std::string from, std::string to, bool system, std::string msg);
+	void format_and_add_chat(const std::string& from, const std::string& to, bool system, const std::string& msg);
 
 	/// The connection to the metaserver
 	std::unique_ptr<NetClient> net;

=== modified file 'src/notifications/notifications_impl.h'
--- src/notifications/notifications_impl.h	2017-02-14 18:11:53 +0000
+++ src/notifications/notifications_impl.h	2017-06-24 11:37:18 +0000
@@ -35,7 +35,7 @@
 // Subscribes to a notification type and unsubscribes on destruction.
 template <typename T> class Subscriber {
 public:
-	Subscriber(uint32_t id, std::function<void(const T&)> callback) : id_(id), callback_(callback) {
+	Subscriber(uint32_t id, const std::function<void(const T&)>& callback) : id_(id), callback_(callback) {
 	}
 
 	~Subscriber();

=== modified file 'src/wlapplication.h'
--- src/wlapplication.h	2017-01-25 18:55:59 +0000
+++ src/wlapplication.h	2017-06-24 11:37:18 +0000
@@ -46,7 +46,7 @@
 struct ParameterError : public std::runtime_error {
 	explicit ParameterError() : std::runtime_error("") {
 	}
-	explicit ParameterError(std::string text) : std::runtime_error(text) {
+	explicit ParameterError(const std::string& text) : std::runtime_error(text) {
 	}
 };
 

=== modified file 'src/wui/game_debug_ui.cc'
--- src/wui/game_debug_ui.cc	2017-02-23 19:38:51 +0000
+++ src/wui/game_debug_ui.cc	2017-06-24 11:37:18 +0000
@@ -47,7 +47,7 @@
 	MapObjectDebugPanel(UI::Panel& parent, const Widelands::EditorGameBase&, Widelands::MapObject&);
 	~MapObjectDebugPanel();
 
-	void log(std::string str) override;
+	void log(const std::string& str) override;
 
 private:
 	const Widelands::EditorGameBase& egbase_;
@@ -85,7 +85,7 @@
 Append the string to the log textarea.
 ===============
 */
-void MapObjectDebugPanel::log(std::string str) {
+void MapObjectDebugPanel::log(const std::string& str) {
 	log_.set_text((log_.get_text() + str).c_str());
 }
 

=== modified file 'src/wui/game_main_menu_save_game.cc'
--- src/wui/game_main_menu_save_game.cc	2017-02-26 12:16:09 +0000
+++ src/wui/game_main_menu_save_game.cc	2017-06-24 11:37:18 +0000
@@ -197,7 +197,7 @@
 	edit_box_changed();
 }
 
-void GameMainMenuSaveGame::select_by_name(std::string name) {
+void GameMainMenuSaveGame::select_by_name(const std::string& name) {
 	for (uint32_t idx = 0; idx < ls_.size(); idx++) {
 		const std::string val = ls_[idx];
 		if (name == val) {

=== modified file 'src/wui/game_main_menu_save_game.h'
--- src/wui/game_main_menu_save_game.h	2017-01-25 18:55:59 +0000
+++ src/wui/game_main_menu_save_game.h	2017-06-24 11:37:18 +0000
@@ -36,7 +36,7 @@
 	GameMainMenuSaveGame(InteractiveGameBase&, UI::UniqueWindow::Registry& registry);
 
 	void fill_list();
-	void select_by_name(std::string name);
+	void select_by_name(const std::string& name);
 
 protected:
 	void die() override;

=== modified file 'src/wui/game_message_menu.cc'
--- src/wui/game_message_menu.cc	2017-06-23 08:33:03 +0000
+++ src/wui/game_message_menu.cc	2017-06-24 11:37:18 +0000
@@ -555,7 +555,7 @@
 /**
  * Get the filename for a message category's icon
  */
-std::string GameMessageMenu::display_message_type_icon(Widelands::Message message) {
+std::string GameMessageMenu::display_message_type_icon(const Widelands::Message& message) {
 	switch (message.message_type_category()) {
 	case Widelands::Message::Type::kGeologists:
 		return "images/wui/fieldaction/menu_geologist.png";

=== modified file 'src/wui/game_message_menu.h'
--- src/wui/game_message_menu.h	2017-01-26 09:28:40 +0000
+++ src/wui/game_message_menu.h	2017-06-24 11:37:18 +0000
@@ -67,7 +67,7 @@
 	void filter_messages(Widelands::Message::Type);
 	void toggle_filter_messages_button(UI::Button&, Widelands::Message::Type);
 	void set_filter_messages_tooltips();
-	std::string display_message_type_icon(Widelands::Message);
+	std::string display_message_type_icon(const Widelands::Message&);
 	void update_record(UI::Table<uintptr_t>::EntryRecord& er, const Widelands::Message&);
 	void update_archive_button_tooltip();
 


Follow ups