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

Proposed by GunChleoc
Status: Merged
Merged at revision: 8389
Proposed branch: lp:~widelands-dev/widelands/bug-986611-cppcheck-pass-by-reference
Merge into: lp:widelands
Diff against target: 315 lines (+29/-30)
20 files modified
src/base/i18n.cc (+2/-2)
src/base/i18n.h (+2/-2)
src/editor/tools/tool_action.h (+1/-1)
src/graphic/text/rt_errors_impl.h (+1/-1)
src/graphic/text/rt_parse.h (+1/-1)
src/graphic/text/textstream.cc (+2/-2)
src/graphic/text/textstream.h (+2/-3)
src/logic/map_objects/map_object.h (+1/-1)
src/logic/map_objects/tribes/tribe_basic_info.h (+1/-1)
src/network/gamehost.cc (+2/-2)
src/network/gamehost.h (+2/-2)
src/network/internet_gaming.cc (+3/-3)
src/network/internet_gaming.h (+1/-1)
src/notifications/notifications_impl.h (+1/-1)
src/wlapplication.h (+1/-1)
src/wui/game_debug_ui.cc (+2/-2)
src/wui/game_main_menu_save_game.cc (+1/-1)
src/wui/game_main_menu_save_game.h (+1/-1)
src/wui/game_message_menu.cc (+1/-1)
src/wui/game_message_menu.h (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-986611-cppcheck-pass-by-reference
Reviewer Review Type Date Requested Status
SirVer Needs Fixing
Review via email: mp+326257@code.launchpad.net

Commit message

Pass function arguments per const reference where possible.

Description of the change

This cleanup should gain us a bit of performance. Changes are pretty trivial (argument -> (const) argument&)

To post a comment you must log in.
Revision history for this message
SirVer (sirver) :
review: Needs Fixing
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review - I have reverted those changes.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2360. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/246575895.
Appveyor build 2188. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_986611_cppcheck_pass_by_reference-2188.

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/base/i18n.cc'
--- src/base/i18n.cc 2017-01-25 18:55:59 +0000
+++ src/base/i18n.cc 2017-06-25 21:56:19 +0000
@@ -76,7 +76,7 @@
76/**76/**
77 * Set the localedir. This should usually only be done once77 * Set the localedir. This should usually only be done once
78 */78 */
79void set_localedir(std::string dname) {79void set_localedir(const std::string& dname) {
80 localedir = dname;80 localedir = dname;
81}81}
8282
@@ -157,7 +157,7 @@
157 * Set the locale to the given string.157 * Set the locale to the given string.
158 * Code inspired by wesnoth.org158 * Code inspired by wesnoth.org
159 */159 */
160void set_locale(std::string name) {160void set_locale(const std::string& name) {
161 const std::map<std::string, std::string> kAlternatives = {161 const std::map<std::string, std::string> kAlternatives = {
162 {"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_"162 {"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_"
163 "QA,ar_SA,ar_SD,ar_SY,ar_TN,ar_YE"},163 "QA,ar_SA,ar_SD,ar_SY,ar_TN,ar_YE"},
164164
=== modified file 'src/base/i18n.h'
--- src/base/i18n.h 2017-06-24 08:47:46 +0000
+++ src/base/i18n.h 2017-06-25 21:56:19 +0000
@@ -52,10 +52,10 @@
52};52};
5353
54void init_locale();54void init_locale();
55void set_locale(std::string);55void set_locale(const std::string&);
56const std::string& get_locale();56const std::string& get_locale();
5757
58void set_localedir(std::string);58void set_localedir(const std::string&);
59const std::string& get_localedir();59const std::string& get_localedir();
6060
61// Localize a list of 'items'. The last 2 items are concatenated with "and" or61// Localize a list of 'items'. The last 2 items are concatenated with "and" or
6262
=== 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-25 21:56:19 +0000
@@ -46,7 +46,7 @@
46 Widelands::Map& m,46 Widelands::Map& m,
47 Widelands::NodeAndTriangle<> c,47 Widelands::NodeAndTriangle<> c,
48 EditorInteractive& p,48 EditorInteractive& p,
49 EditorActionArgs nargs)49 const EditorActionArgs& nargs)
50 : tool(t), i(ind), map(m), center(c), parent(p) {50 : tool(t), i(ind), map(m), center(c), parent(p) {
51 args = new EditorActionArgs(parent);51 args = new EditorActionArgs(parent);
52 *args = nargs;52 *args = nargs;
5353
=== 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-25 21:56:19 +0000
@@ -28,7 +28,7 @@
2828
29struct SyntaxErrorImpl : public SyntaxError {29struct SyntaxErrorImpl : public SyntaxError {
30 SyntaxErrorImpl(30 SyntaxErrorImpl(
31 size_t line, size_t col, std::string expected, std::string got, std::string next_chars)31 size_t line, size_t col, const std::string& expected, const std::string& got, const std::string& next_chars)
32 : SyntaxError(32 : SyntaxError(
33 (boost::format(33 (boost::format(
34 "Syntax error at %1%:%2%: expected %3%, got '%4%'. String continues with: '%5%'") %34 "Syntax error at %1%:%2%: expected %3%, got '%4%'. String continues with: '%5%'") %
3535
=== modified file 'src/graphic/text/rt_parse.h'
--- src/graphic/text/rt_parse.h 2017-06-24 08:47:46 +0000
+++ src/graphic/text/rt_parse.h 2017-06-25 21:56:19 +0000
@@ -104,7 +104,7 @@
104 }104 }
105 explicit Child(Tag* t) : tag(t) {105 explicit Child(Tag* t) : tag(t) {
106 }106 }
107 explicit Child(std::string t) : tag(nullptr), text(t) {107 explicit Child(const std::string& t) : tag(nullptr), text(t) {
108 }108 }
109 ~Child() {109 ~Child() {
110 if (tag)110 if (tag)
111111
=== 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-25 21:56:19 +0000
@@ -29,7 +29,7 @@
29namespace RT {29namespace RT {
3030
31struct EndOfTextImpl : public EndOfText {31struct EndOfTextImpl : public EndOfText {
32 EndOfTextImpl(size_t pos, std::string text)32 EndOfTextImpl(size_t pos, const std::string& text)
33 : EndOfText(33 : EndOfText(
34 (format("Unexpected End of Text, starting at %1%. Text is: '%2%'") % pos % text).str()) {34 (format("Unexpected End of Text, starting at %1%. Text is: '%2%'") % pos % text).str()) {
35 }35 }
@@ -133,7 +133,7 @@
133/*133/*
134 * Parse till any of the chars is found or the end of the string has been hit.134 * Parse till any of the chars is found or the end of the string has been hit.
135 */135 */
136std::string TextStream::till_any_or_end(std::string chars) {136std::string TextStream::till_any_or_end(const std::string& chars) {
137 std::string rv;137 std::string rv;
138 try {138 try {
139 rv = till_any(chars);139 rv = till_any(chars);
140140
=== modified file 'src/graphic/text/textstream.h'
--- src/graphic/text/textstream.h 2017-06-25 19:12:30 +0000
+++ src/graphic/text/textstream.h 2017-06-25 21:56:19 +0000
@@ -28,8 +28,7 @@
2828
29class TextStream {29class TextStream {
30public:30public:
31 explicit TextStream(std::string text)31 explicit TextStream(const std::string& text) : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {
32 : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {
33 }32 }
3433
35 size_t line() const {34 size_t line() const {
@@ -46,7 +45,7 @@
46 void expect(std::string, bool = true);45 void expect(std::string, bool = true);
4746
48 std::string till_any(std::string);47 std::string till_any(std::string);
49 std::string till_any_or_end(std::string);48 std::string till_any_or_end(const std::string&);
50 std::string parse_string();49 std::string parse_string();
5150
52 void skip(size_t d) {51 void skip(size_t d) {
5352
=== modified file 'src/logic/map_objects/map_object.h'
--- src/logic/map_objects/map_object.h 2017-06-25 19:12:30 +0000
+++ src/logic/map_objects/map_object.h 2017-06-25 21:56:19 +0000
@@ -241,7 +241,7 @@
241 };241 };
242242
243 struct LogSink {243 struct LogSink {
244 virtual void log(std::string str) = 0;244 virtual void log(const std::string& str) = 0;
245 virtual ~LogSink() {245 virtual ~LogSink() {
246 }246 }
247 };247 };
248248
=== modified file 'src/logic/map_objects/tribes/tribe_basic_info.h'
--- src/logic/map_objects/tribes/tribe_basic_info.h 2017-06-24 08:47:46 +0000
+++ src/logic/map_objects/tribes/tribe_basic_info.h 2017-06-25 21:56:19 +0000
@@ -34,7 +34,7 @@
3434
35 /// Script path and localized name for a starting condition35 /// Script path and localized name for a starting condition
36 struct Initialization {36 struct Initialization {
37 Initialization(std::string init_script, std::string init_descname, std::string init_tooltip)37 Initialization(const std::string& init_script, const std::string& init_descname, const std::string& init_tooltip)
38 : script(init_script), descname(init_descname), tooltip(init_tooltip) {38 : script(init_script), descname(init_descname), tooltip(init_tooltip) {
39 }39 }
40 std::string script;40 std::string script;
4141
=== modified file 'src/network/gamehost.cc'
--- src/network/gamehost.cc 2017-06-24 08:47:46 +0000
+++ src/network/gamehost.cc 2017-06-25 21:56:19 +0000
@@ -909,7 +909,7 @@
909 * - -1 if no client was found909 * - -1 if no client was found
910 * - -2 if the host is the client (has no client number)910 * - -2 if the host is the client (has no client number)
911 */911 */
912int32_t GameHost::check_client(std::string name) {912int32_t GameHost::check_client(const std::string& name) {
913 // Check if the client is the host him-/herself913 // Check if the client is the host him-/herself
914 if (d->localplayername == name) {914 if (d->localplayername == name) {
915 return -2;915 return -2;
@@ -939,7 +939,7 @@
939* If the host sends a chat message with formation /kick <name> <reason>939* If the host sends a chat message with formation /kick <name> <reason>
940* This function will handle this command and try to kick the user.940* This function will handle this command and try to kick the user.
941*/941*/
942void GameHost::kick_user(uint32_t client, std::string reason) {942void GameHost::kick_user(uint32_t client, const std::string& reason) {
943 disconnect_client(client, "KICKED", true, reason);943 disconnect_client(client, "KICKED", true, reason);
944}944}
945945
946946
=== modified file 'src/network/gamehost.h'
--- src/network/gamehost.h 2017-06-05 07:33:18 +0000
+++ src/network/gamehost.h 2017-06-25 21:56:19 +0000
@@ -87,8 +87,8 @@
87 void send(ChatMessage msg);87 void send(ChatMessage msg);
8888
89 // Host command related stuff89 // Host command related stuff
90 int32_t check_client(std::string name);90 int32_t check_client(const std::string& name);
91 void kick_user(uint32_t, std::string);91 void kick_user(uint32_t, const std::string&);
92 void split_command_array(const std::string& cmdarray,92 void split_command_array(const std::string& cmdarray,
93 std::string& cmd,93 std::string& cmd,
94 std::string& arg1,94 std::string& arg1,
9595
=== 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-25 21:56:19 +0000
@@ -803,10 +803,10 @@
803}803}
804804
805/// formates a chat message and adds it to the list of chat messages805/// formates a chat message and adds it to the list of chat messages
806void InternetGaming::format_and_add_chat(std::string from,806void InternetGaming::format_and_add_chat(const std::string& from,
807 std::string to,807 const std::string& to,
808 bool system,808 bool system,
809 std::string msg) {809 const std::string& msg) {
810 ChatMessage c;810 ChatMessage c;
811 if (!system && from.empty()) {811 if (!system && from.empty()) {
812 std::string unkown_string = (boost::format("<%s>") % _("unknown")).str();812 std::string unkown_string = (boost::format("<%s>") % _("unknown")).str();
813813
=== 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-25 21:56:19 +0000
@@ -153,7 +153,7 @@
153 bool str2bool(std::string);153 bool str2bool(std::string);
154 std::string bool2str(bool);154 std::string bool2str(bool);
155155
156 void format_and_add_chat(std::string from, std::string to, bool system, std::string msg);156 void format_and_add_chat(const std::string& from, const std::string& to, bool system, const std::string& msg);
157157
158 /// The connection to the metaserver158 /// The connection to the metaserver
159 std::unique_ptr<NetClient> net;159 std::unique_ptr<NetClient> net;
160160
=== 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-25 21:56:19 +0000
@@ -35,7 +35,7 @@
35// Subscribes to a notification type and unsubscribes on destruction.35// Subscribes to a notification type and unsubscribes on destruction.
36template <typename T> class Subscriber {36template <typename T> class Subscriber {
37public:37public:
38 Subscriber(uint32_t id, std::function<void(const T&)> callback) : id_(id), callback_(callback) {38 Subscriber(uint32_t id, const std::function<void(const T&)>& callback) : id_(id), callback_(callback) {
39 }39 }
4040
41 ~Subscriber();41 ~Subscriber();
4242
=== modified file 'src/wlapplication.h'
--- src/wlapplication.h 2017-01-25 18:55:59 +0000
+++ src/wlapplication.h 2017-06-25 21:56:19 +0000
@@ -46,7 +46,7 @@
46struct ParameterError : public std::runtime_error {46struct ParameterError : public std::runtime_error {
47 explicit ParameterError() : std::runtime_error("") {47 explicit ParameterError() : std::runtime_error("") {
48 }48 }
49 explicit ParameterError(std::string text) : std::runtime_error(text) {49 explicit ParameterError(const std::string& text) : std::runtime_error(text) {
50 }50 }
51};51};
5252
5353
=== 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-25 21:56:19 +0000
@@ -47,7 +47,7 @@
47 MapObjectDebugPanel(UI::Panel& parent, const Widelands::EditorGameBase&, Widelands::MapObject&);47 MapObjectDebugPanel(UI::Panel& parent, const Widelands::EditorGameBase&, Widelands::MapObject&);
48 ~MapObjectDebugPanel();48 ~MapObjectDebugPanel();
4949
50 void log(std::string str) override;50 void log(const std::string& str) override;
5151
52private:52private:
53 const Widelands::EditorGameBase& egbase_;53 const Widelands::EditorGameBase& egbase_;
@@ -85,7 +85,7 @@
85Append the string to the log textarea.85Append the string to the log textarea.
86===============86===============
87*/87*/
88void MapObjectDebugPanel::log(std::string str) {88void MapObjectDebugPanel::log(const std::string& str) {
89 log_.set_text((log_.get_text() + str).c_str());89 log_.set_text((log_.get_text() + str).c_str());
90}90}
9191
9292
=== 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-25 21:56:19 +0000
@@ -197,7 +197,7 @@
197 edit_box_changed();197 edit_box_changed();
198}198}
199199
200void GameMainMenuSaveGame::select_by_name(std::string name) {200void GameMainMenuSaveGame::select_by_name(const std::string& name) {
201 for (uint32_t idx = 0; idx < ls_.size(); idx++) {201 for (uint32_t idx = 0; idx < ls_.size(); idx++) {
202 const std::string val = ls_[idx];202 const std::string val = ls_[idx];
203 if (name == val) {203 if (name == val) {
204204
=== 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-25 21:56:19 +0000
@@ -36,7 +36,7 @@
36 GameMainMenuSaveGame(InteractiveGameBase&, UI::UniqueWindow::Registry& registry);36 GameMainMenuSaveGame(InteractiveGameBase&, UI::UniqueWindow::Registry& registry);
3737
38 void fill_list();38 void fill_list();
39 void select_by_name(std::string name);39 void select_by_name(const std::string& name);
4040
41protected:41protected:
42 void die() override;42 void die() override;
4343
=== 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-25 21:56:19 +0000
@@ -555,7 +555,7 @@
555/**555/**
556 * Get the filename for a message category's icon556 * Get the filename for a message category's icon
557 */557 */
558std::string GameMessageMenu::display_message_type_icon(Widelands::Message message) {558std::string GameMessageMenu::display_message_type_icon(const Widelands::Message& message) {
559 switch (message.message_type_category()) {559 switch (message.message_type_category()) {
560 case Widelands::Message::Type::kGeologists:560 case Widelands::Message::Type::kGeologists:
561 return "images/wui/fieldaction/menu_geologist.png";561 return "images/wui/fieldaction/menu_geologist.png";
562562
=== 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-25 21:56:19 +0000
@@ -67,7 +67,7 @@
67 void filter_messages(Widelands::Message::Type);67 void filter_messages(Widelands::Message::Type);
68 void toggle_filter_messages_button(UI::Button&, Widelands::Message::Type);68 void toggle_filter_messages_button(UI::Button&, Widelands::Message::Type);
69 void set_filter_messages_tooltips();69 void set_filter_messages_tooltips();
70 std::string display_message_type_icon(Widelands::Message);70 std::string display_message_type_icon(const Widelands::Message&);
71 void update_record(UI::Table<uintptr_t>::EntryRecord& er, const Widelands::Message&);71 void update_record(UI::Table<uintptr_t>::EntryRecord& er, const Widelands::Message&);
72 void update_archive_button_tooltip();72 void update_archive_button_tooltip();
7373

Subscribers

People subscribed via source and target branches

to status/vote changes: