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
1=== modified file 'src/base/i18n.cc'
2--- src/base/i18n.cc 2017-01-25 18:55:59 +0000
3+++ src/base/i18n.cc 2017-06-25 21:56:19 +0000
4@@ -76,7 +76,7 @@
5 /**
6 * Set the localedir. This should usually only be done once
7 */
8-void set_localedir(std::string dname) {
9+void set_localedir(const std::string& dname) {
10 localedir = dname;
11 }
12
13@@ -157,7 +157,7 @@
14 * Set the locale to the given string.
15 * Code inspired by wesnoth.org
16 */
17-void set_locale(std::string name) {
18+void set_locale(const std::string& name) {
19 const std::map<std::string, std::string> kAlternatives = {
20 {"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_"
21 "QA,ar_SA,ar_SD,ar_SY,ar_TN,ar_YE"},
22
23=== modified file 'src/base/i18n.h'
24--- src/base/i18n.h 2017-06-24 08:47:46 +0000
25+++ src/base/i18n.h 2017-06-25 21:56:19 +0000
26@@ -52,10 +52,10 @@
27 };
28
29 void init_locale();
30-void set_locale(std::string);
31+void set_locale(const std::string&);
32 const std::string& get_locale();
33
34-void set_localedir(std::string);
35+void set_localedir(const std::string&);
36 const std::string& get_localedir();
37
38 // Localize a list of 'items'. The last 2 items are concatenated with "and" or
39
40=== modified file 'src/editor/tools/tool_action.h'
41--- src/editor/tools/tool_action.h 2017-01-25 18:55:59 +0000
42+++ src/editor/tools/tool_action.h 2017-06-25 21:56:19 +0000
43@@ -46,7 +46,7 @@
44 Widelands::Map& m,
45 Widelands::NodeAndTriangle<> c,
46 EditorInteractive& p,
47- EditorActionArgs nargs)
48+ const EditorActionArgs& nargs)
49 : tool(t), i(ind), map(m), center(c), parent(p) {
50 args = new EditorActionArgs(parent);
51 *args = nargs;
52
53=== modified file 'src/graphic/text/rt_errors_impl.h'
54--- src/graphic/text/rt_errors_impl.h 2017-01-25 18:55:59 +0000
55+++ src/graphic/text/rt_errors_impl.h 2017-06-25 21:56:19 +0000
56@@ -28,7 +28,7 @@
57
58 struct SyntaxErrorImpl : public SyntaxError {
59 SyntaxErrorImpl(
60- size_t line, size_t col, std::string expected, std::string got, std::string next_chars)
61+ size_t line, size_t col, const std::string& expected, const std::string& got, const std::string& next_chars)
62 : SyntaxError(
63 (boost::format(
64 "Syntax error at %1%:%2%: expected %3%, got '%4%'. String continues with: '%5%'") %
65
66=== modified file 'src/graphic/text/rt_parse.h'
67--- src/graphic/text/rt_parse.h 2017-06-24 08:47:46 +0000
68+++ src/graphic/text/rt_parse.h 2017-06-25 21:56:19 +0000
69@@ -104,7 +104,7 @@
70 }
71 explicit Child(Tag* t) : tag(t) {
72 }
73- explicit Child(std::string t) : tag(nullptr), text(t) {
74+ explicit Child(const std::string& t) : tag(nullptr), text(t) {
75 }
76 ~Child() {
77 if (tag)
78
79=== modified file 'src/graphic/text/textstream.cc'
80--- src/graphic/text/textstream.cc 2017-05-31 21:27:07 +0000
81+++ src/graphic/text/textstream.cc 2017-06-25 21:56:19 +0000
82@@ -29,7 +29,7 @@
83 namespace RT {
84
85 struct EndOfTextImpl : public EndOfText {
86- EndOfTextImpl(size_t pos, std::string text)
87+ EndOfTextImpl(size_t pos, const std::string& text)
88 : EndOfText(
89 (format("Unexpected End of Text, starting at %1%. Text is: '%2%'") % pos % text).str()) {
90 }
91@@ -133,7 +133,7 @@
92 /*
93 * Parse till any of the chars is found or the end of the string has been hit.
94 */
95-std::string TextStream::till_any_or_end(std::string chars) {
96+std::string TextStream::till_any_or_end(const std::string& chars) {
97 std::string rv;
98 try {
99 rv = till_any(chars);
100
101=== modified file 'src/graphic/text/textstream.h'
102--- src/graphic/text/textstream.h 2017-06-25 19:12:30 +0000
103+++ src/graphic/text/textstream.h 2017-06-25 21:56:19 +0000
104@@ -28,8 +28,7 @@
105
106 class TextStream {
107 public:
108- explicit TextStream(std::string text)
109- : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {
110+ explicit TextStream(const std::string& text) : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {
111 }
112
113 size_t line() const {
114@@ -46,7 +45,7 @@
115 void expect(std::string, bool = true);
116
117 std::string till_any(std::string);
118- std::string till_any_or_end(std::string);
119+ std::string till_any_or_end(const std::string&);
120 std::string parse_string();
121
122 void skip(size_t d) {
123
124=== modified file 'src/logic/map_objects/map_object.h'
125--- src/logic/map_objects/map_object.h 2017-06-25 19:12:30 +0000
126+++ src/logic/map_objects/map_object.h 2017-06-25 21:56:19 +0000
127@@ -241,7 +241,7 @@
128 };
129
130 struct LogSink {
131- virtual void log(std::string str) = 0;
132+ virtual void log(const std::string& str) = 0;
133 virtual ~LogSink() {
134 }
135 };
136
137=== modified file 'src/logic/map_objects/tribes/tribe_basic_info.h'
138--- src/logic/map_objects/tribes/tribe_basic_info.h 2017-06-24 08:47:46 +0000
139+++ src/logic/map_objects/tribes/tribe_basic_info.h 2017-06-25 21:56:19 +0000
140@@ -34,7 +34,7 @@
141
142 /// Script path and localized name for a starting condition
143 struct Initialization {
144- Initialization(std::string init_script, std::string init_descname, std::string init_tooltip)
145+ Initialization(const std::string& init_script, const std::string& init_descname, const std::string& init_tooltip)
146 : script(init_script), descname(init_descname), tooltip(init_tooltip) {
147 }
148 std::string script;
149
150=== modified file 'src/network/gamehost.cc'
151--- src/network/gamehost.cc 2017-06-24 08:47:46 +0000
152+++ src/network/gamehost.cc 2017-06-25 21:56:19 +0000
153@@ -909,7 +909,7 @@
154 * - -1 if no client was found
155 * - -2 if the host is the client (has no client number)
156 */
157-int32_t GameHost::check_client(std::string name) {
158+int32_t GameHost::check_client(const std::string& name) {
159 // Check if the client is the host him-/herself
160 if (d->localplayername == name) {
161 return -2;
162@@ -939,7 +939,7 @@
163 * If the host sends a chat message with formation /kick <name> <reason>
164 * This function will handle this command and try to kick the user.
165 */
166-void GameHost::kick_user(uint32_t client, std::string reason) {
167+void GameHost::kick_user(uint32_t client, const std::string& reason) {
168 disconnect_client(client, "KICKED", true, reason);
169 }
170
171
172=== modified file 'src/network/gamehost.h'
173--- src/network/gamehost.h 2017-06-05 07:33:18 +0000
174+++ src/network/gamehost.h 2017-06-25 21:56:19 +0000
175@@ -87,8 +87,8 @@
176 void send(ChatMessage msg);
177
178 // Host command related stuff
179- int32_t check_client(std::string name);
180- void kick_user(uint32_t, std::string);
181+ int32_t check_client(const std::string& name);
182+ void kick_user(uint32_t, const std::string&);
183 void split_command_array(const std::string& cmdarray,
184 std::string& cmd,
185 std::string& arg1,
186
187=== modified file 'src/network/internet_gaming.cc'
188--- src/network/internet_gaming.cc 2017-06-04 16:01:13 +0000
189+++ src/network/internet_gaming.cc 2017-06-25 21:56:19 +0000
190@@ -803,10 +803,10 @@
191 }
192
193 /// formates a chat message and adds it to the list of chat messages
194-void InternetGaming::format_and_add_chat(std::string from,
195- std::string to,
196+void InternetGaming::format_and_add_chat(const std::string& from,
197+ const std::string& to,
198 bool system,
199- std::string msg) {
200+ const std::string& msg) {
201 ChatMessage c;
202 if (!system && from.empty()) {
203 std::string unkown_string = (boost::format("<%s>") % _("unknown")).str();
204
205=== modified file 'src/network/internet_gaming.h'
206--- src/network/internet_gaming.h 2017-06-03 05:27:36 +0000
207+++ src/network/internet_gaming.h 2017-06-25 21:56:19 +0000
208@@ -153,7 +153,7 @@
209 bool str2bool(std::string);
210 std::string bool2str(bool);
211
212- void format_and_add_chat(std::string from, std::string to, bool system, std::string msg);
213+ void format_and_add_chat(const std::string& from, const std::string& to, bool system, const std::string& msg);
214
215 /// The connection to the metaserver
216 std::unique_ptr<NetClient> net;
217
218=== modified file 'src/notifications/notifications_impl.h'
219--- src/notifications/notifications_impl.h 2017-02-14 18:11:53 +0000
220+++ src/notifications/notifications_impl.h 2017-06-25 21:56:19 +0000
221@@ -35,7 +35,7 @@
222 // Subscribes to a notification type and unsubscribes on destruction.
223 template <typename T> class Subscriber {
224 public:
225- Subscriber(uint32_t id, std::function<void(const T&)> callback) : id_(id), callback_(callback) {
226+ Subscriber(uint32_t id, const std::function<void(const T&)>& callback) : id_(id), callback_(callback) {
227 }
228
229 ~Subscriber();
230
231=== modified file 'src/wlapplication.h'
232--- src/wlapplication.h 2017-01-25 18:55:59 +0000
233+++ src/wlapplication.h 2017-06-25 21:56:19 +0000
234@@ -46,7 +46,7 @@
235 struct ParameterError : public std::runtime_error {
236 explicit ParameterError() : std::runtime_error("") {
237 }
238- explicit ParameterError(std::string text) : std::runtime_error(text) {
239+ explicit ParameterError(const std::string& text) : std::runtime_error(text) {
240 }
241 };
242
243
244=== modified file 'src/wui/game_debug_ui.cc'
245--- src/wui/game_debug_ui.cc 2017-02-23 19:38:51 +0000
246+++ src/wui/game_debug_ui.cc 2017-06-25 21:56:19 +0000
247@@ -47,7 +47,7 @@
248 MapObjectDebugPanel(UI::Panel& parent, const Widelands::EditorGameBase&, Widelands::MapObject&);
249 ~MapObjectDebugPanel();
250
251- void log(std::string str) override;
252+ void log(const std::string& str) override;
253
254 private:
255 const Widelands::EditorGameBase& egbase_;
256@@ -85,7 +85,7 @@
257 Append the string to the log textarea.
258 ===============
259 */
260-void MapObjectDebugPanel::log(std::string str) {
261+void MapObjectDebugPanel::log(const std::string& str) {
262 log_.set_text((log_.get_text() + str).c_str());
263 }
264
265
266=== modified file 'src/wui/game_main_menu_save_game.cc'
267--- src/wui/game_main_menu_save_game.cc 2017-02-26 12:16:09 +0000
268+++ src/wui/game_main_menu_save_game.cc 2017-06-25 21:56:19 +0000
269@@ -197,7 +197,7 @@
270 edit_box_changed();
271 }
272
273-void GameMainMenuSaveGame::select_by_name(std::string name) {
274+void GameMainMenuSaveGame::select_by_name(const std::string& name) {
275 for (uint32_t idx = 0; idx < ls_.size(); idx++) {
276 const std::string val = ls_[idx];
277 if (name == val) {
278
279=== modified file 'src/wui/game_main_menu_save_game.h'
280--- src/wui/game_main_menu_save_game.h 2017-01-25 18:55:59 +0000
281+++ src/wui/game_main_menu_save_game.h 2017-06-25 21:56:19 +0000
282@@ -36,7 +36,7 @@
283 GameMainMenuSaveGame(InteractiveGameBase&, UI::UniqueWindow::Registry& registry);
284
285 void fill_list();
286- void select_by_name(std::string name);
287+ void select_by_name(const std::string& name);
288
289 protected:
290 void die() override;
291
292=== modified file 'src/wui/game_message_menu.cc'
293--- src/wui/game_message_menu.cc 2017-06-23 08:33:03 +0000
294+++ src/wui/game_message_menu.cc 2017-06-25 21:56:19 +0000
295@@ -555,7 +555,7 @@
296 /**
297 * Get the filename for a message category's icon
298 */
299-std::string GameMessageMenu::display_message_type_icon(Widelands::Message message) {
300+std::string GameMessageMenu::display_message_type_icon(const Widelands::Message& message) {
301 switch (message.message_type_category()) {
302 case Widelands::Message::Type::kGeologists:
303 return "images/wui/fieldaction/menu_geologist.png";
304
305=== modified file 'src/wui/game_message_menu.h'
306--- src/wui/game_message_menu.h 2017-01-26 09:28:40 +0000
307+++ src/wui/game_message_menu.h 2017-06-25 21:56:19 +0000
308@@ -67,7 +67,7 @@
309 void filter_messages(Widelands::Message::Type);
310 void toggle_filter_messages_button(UI::Button&, Widelands::Message::Type);
311 void set_filter_messages_tooltips();
312- std::string display_message_type_icon(Widelands::Message);
313+ std::string display_message_type_icon(const Widelands::Message&);
314 void update_record(UI::Table<uintptr_t>::EntryRecord& er, const Widelands::Message&);
315 void update_archive_button_tooltip();
316

Subscribers

People subscribed via source and target branches

to status/vote changes: