Merge lp:~mc-return/unity/unity.merge-optimize-performance-and-style into lp:unity

Proposed by MC Return on 2012-07-30
Status: Merged
Approved by: Łukasz Zemczak on 2012-08-03
Approved revision: 2550
Merged at revision: 2534
Proposed branch: lp:~mc-return/unity/unity.merge-optimize-performance-and-style
Merge into: lp:unity
Diff against target: 420 lines (+34/-39)
18 files modified
UnityCore/HomeLens.cpp (+3/-3)
dash/ResultView.cpp (+1/-1)
dash/ResultViewGrid.cpp (+1/-1)
launcher/Launcher.cpp (+8/-8)
launcher/LauncherController.cpp (+1/-1)
launcher/LauncherModel.cpp (+3/-3)
panel/PanelIndicatorEntryView.cpp (+1/-2)
panel/PanelMenuView.cpp (+1/-1)
plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp (+1/-1)
plugins/unitydialog/src/unitydialog.cpp (+3/-4)
plugins/unityshell/src/nux-layout-accessible.cpp (+1/-1)
plugins/unityshell/src/unity-launcher-accessible.cpp (+1/-1)
plugins/unityshell/src/unity-switcher-accessible.cpp (+1/-1)
plugins/unityshell/src/unityshell.cpp (+3/-5)
unity-shared/BGHash.cpp (+1/-1)
unity-shared/DashStyle.cpp (+1/-1)
unity-shared/IconRenderer.cpp (+2/-3)
unity-shared/PluginAdapterCompiz.cpp (+1/-1)
To merge this branch: bzr merge lp:~mc-return/unity/unity.merge-optimize-performance-and-style
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve on 2012-07-30
MC Return (community) Resubmit on 2012-07-30
Marco Trevisan (Treviño) 2012-07-30 Approve on 2012-07-30
Review via email: mp+117310@code.launchpad.net

Commit Message

Optimized performance and style following suggestions reported by cppcheck:

1. Reduced the scope of various variables.

2. Used prefix ++ operators for non-primitive types, because those can be more efficient than post-increment. Post-increment usually keeps a copy of the previous value, adds extra code and is slower.

Description of the Change

Optimized performance and style following suggestions reported by cppcheck:

1. Reduced the scope of various variables.

2. Used prefix ++ operators for non-primitive types, because those can be more efficient than post-increment. Post-increment usually keeps a copy of the previous value, adds extra code and is slower.

To post a comment you must log in.
Marco Trevisan (Treviño) (3v1n0) wrote :

Nice, thanks!

review: Approve
Unity Merger (unity-merger) wrote :

No commit message specified.

MC Return (mc-return) wrote :

> No commit message specified.

Fixed.

review: Resubmit
Brandon Schaefer (brandontschaefer) wrote :

Looks good, Thank you!

review: Approve
Unity Merger (unity-merger) wrote :
Andrea Azzarone (azzar1) wrote :

I prefer to use pre-increment operator for primitive types too.

Unity Merger (unity-merger) wrote :
Unity Merger (unity-merger) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/HomeLens.cpp'
2--- UnityCore/HomeLens.cpp 2012-03-30 10:29:51 +0000
3+++ UnityCore/HomeLens.cpp 2012-07-30 17:43:18 +0000
4@@ -105,7 +105,7 @@
5 /* Any existing categories with offsets >= target_cat_offset must be
6 * pushed up. Update both maps by id and display name */
7 std::map<std::string,unsigned int>::iterator end = reg_by_id_.end();
8- for (i = reg_by_id_.begin(); i != end; i++)
9+ for (i = reg_by_id_.begin(); i != end; ++i)
10 {
11 if (i->second >= target_cat_offset)
12 {
13@@ -114,7 +114,7 @@
14 }
15 }
16
17- for (i = reg_by_display_name_.begin(), end = reg_by_display_name_.end(); i != end; i++)
18+ for (i = reg_by_display_name_.begin(), end = reg_by_display_name_.end(); i != end; ++i)
19 {
20 if (i->second >= target_cat_offset)
21 {
22@@ -637,7 +637,7 @@
23 * the category offset in the corresponding rows in the target model
24 */
25 for (i = source_to_target_tags_.begin(), end = source_to_target_tags_.end();
26- i != end; i++)
27+ i != end; ++i)
28 {
29 source = i->first;
30 target_tag = i->second;
31
32=== modified file 'dash/ResultView.cpp'
33--- dash/ResultView.cpp 2012-07-04 02:37:23 +0000
34+++ dash/ResultView.cpp 2012-07-30 17:43:18 +0000
35@@ -97,7 +97,7 @@
36 ResultList::iterator it;
37 std::string uri = result.uri;
38
39- for (it = results_.begin(); it != results_.end(); it++)
40+ for (it = results_.begin(); it != results_.end(); ++it)
41 {
42 if (result.uri == (*it).uri)
43 {
44
45=== modified file 'dash/ResultViewGrid.cpp'
46--- dash/ResultViewGrid.cpp 2012-07-04 02:37:23 +0000
47+++ dash/ResultViewGrid.cpp 2012-07-30 17:43:18 +0000
48@@ -354,7 +354,7 @@
49 total_rows = (expanded) ? total_rows : 1; // restrict to one row if not expanded
50
51 // find the currently focused item
52- for (it = results_.begin(); it != results_.end(); it++)
53+ for (it = results_.begin(); it != results_.end(); ++it)
54 {
55 std::string result_uri = (*it).uri;
56 if (result_uri == focused_uri_)
57
58=== modified file 'launcher/Launcher.cpp'
59--- launcher/Launcher.cpp 2012-07-27 11:49:35 +0000
60+++ launcher/Launcher.cpp 2012-07-30 17:43:18 +0000
61@@ -473,7 +473,7 @@
62
63 // animations happening on specific icons
64 LauncherModel::iterator it;
65- for (it = _model->begin(); it != _model->end(); it++)
66+ for (it = _model->begin(); it != _model->end(); ++it)
67 if (IconNeedsAnimation(*it, current))
68 return true;
69
70@@ -997,7 +997,7 @@
71 // compute required height of launcher AND folding threshold
72 float sum = 0.0f + center.y;
73 float folding_threshold = launcher_height - _icon_size / 2.5f;
74- for (it = _model->begin(); it != _model->end(); it++)
75+ for (it = _model->begin(); it != _model->end(); ++it)
76 {
77 float height = (_icon_size + _space_between_icons) * IconVisibleProgress(*it, current);
78 sum += height;
79@@ -1106,7 +1106,7 @@
80 // wont start jumping around). As a general rule ANY if () statements that modify center.y should be seen
81 // as bugs.
82 int index = 1;
83- for (it = _model->main_begin(); it != _model->main_end(); it++)
84+ for (it = _model->main_begin(); it != _model->main_end(); ++it)
85 {
86 RenderArg arg;
87 AbstractLauncherIcon::Ptr icon = *it;
88@@ -1120,7 +1120,7 @@
89
90 // compute maximum height of shelf
91 float shelf_sum = 0.0f;
92- for (it = _model->shelf_begin(); it != _model->shelf_end(); it++)
93+ for (it = _model->shelf_begin(); it != _model->shelf_end(); ++it)
94 {
95 float height = (_icon_size + _space_between_icons) * IconVisibleProgress(*it, current);
96 shelf_sum += height;
97@@ -1134,7 +1134,7 @@
98 folding_threshold += shelf_delta;
99 center.y += shelf_delta;
100
101- for (it = _model->shelf_begin(); it != _model->shelf_end(); it++)
102+ for (it = _model->shelf_begin(); it != _model->shelf_end(); ++it)
103 {
104 RenderArg arg;
105 AbstractLauncherIcon::Ptr icon = *it;
106@@ -1908,7 +1908,7 @@
107 EventLogic();
108
109 /* draw launcher */
110- for (rev_it = args.rbegin(); rev_it != args.rend(); rev_it++)
111+ for (rev_it = args.rbegin(); rev_it != args.rend(); ++rev_it)
112 {
113 if ((*rev_it).stick_thingy)
114 gPainter.Paint2DQuadColor(GfxContext,
115@@ -2114,7 +2114,7 @@
116 AbstractLauncherIcon::Ptr iconBeforeHover;
117 LauncherModel::iterator it;
118 LauncherModel::iterator prevIt = _model->end();
119- for (it = _model->begin(); it != _model->end(); it++)
120+ for (it = _model->begin(); it != _model->end(); ++it)
121 {
122 if (!(*it)->GetQuirk(AbstractLauncherIcon::QUIRK_VISIBLE) || !(*it)->IsVisibleOnMonitor(monitor))
123 continue;
124@@ -2460,7 +2460,7 @@
125 nux::Point2 mouse_position(x, y);
126 int inside = 0;
127
128- for (it = _model->begin(); it != _model->end(); it++)
129+ for (it = _model->begin(); it != _model->end(); ++it)
130 {
131 if (!(*it)->GetQuirk(AbstractLauncherIcon::QUIRK_VISIBLE) || !(*it)->IsVisibleOnMonitor(monitor))
132 continue;
133
134=== modified file 'launcher/LauncherController.cpp'
135--- launcher/LauncherController.cpp 2012-07-25 23:18:17 +0000
136+++ launcher/LauncherController.cpp 2012-07-30 17:43:18 +0000
137@@ -940,7 +940,7 @@
138 LauncherModel::iterator it;
139
140 // Shortcut to start launcher icons. Only relies on Keycode, ignore modifier
141- for (it = pimpl->model_->begin(); it != pimpl->model_->end(); it++)
142+ for (it = pimpl->model_->begin(); it != pimpl->model_->end(); ++it)
143 {
144 if ((XKeysymToKeycode(display, (*it)->GetShortcut()) == key_code) ||
145 ((gchar)((*it)->GetShortcut()) == key_string[0]))
146
147=== modified file 'launcher/LauncherModel.cpp'
148--- launcher/LauncherModel.cpp 2012-07-09 11:21:08 +0000
149+++ launcher/LauncherModel.cpp 2012-07-30 17:43:18 +0000
150@@ -79,14 +79,14 @@
151 iterator it, it2;
152
153 int i = 0;
154- for (it = main_begin(); it != main_end(); it++)
155+ for (it = main_begin(); it != main_end(); ++it)
156 {
157 _inner.push_back(*it);
158 (*it)->SetSortPriority(i);
159 ++i;
160 }
161
162- for (it = shelf_begin(); it != shelf_end(); it++)
163+ for (it = shelf_begin(); it != shelf_end(); ++it)
164 {
165 _inner.push_back(*it);
166 (*it)->SetSortPriority(i);
167@@ -409,7 +409,7 @@
168 int i;
169
170 // start currently selected icon
171- for (it = _inner.begin(), i = 0; it != _inner.end(); it++, i++)
172+ for (it = _inner.begin(), i = 0; it != _inner.end(); ++it, i++)
173 {
174 if (i == index)
175 return it;
176
177=== modified file 'panel/PanelIndicatorEntryView.cpp'
178--- panel/PanelIndicatorEntryView.cpp 2012-05-07 22:28:17 +0000
179+++ panel/PanelIndicatorEntryView.cpp 2012-07-30 17:43:18 +0000
180@@ -429,7 +429,6 @@
181 unsigned int width = 0;
182 unsigned int icon_width = 0;
183 unsigned int height = panel::Style::Instance().panel_height;
184- unsigned int text_width = 0;
185
186 // First lets figure out our size
187 if (pixbuf && IsIconVisible())
188@@ -484,7 +483,7 @@
189 pango_layout_context_changed(layout);
190
191 pango_layout_get_extents(layout, nullptr, &log_rect);
192- text_width = log_rect.width / PANGO_SCALE;
193+ unsigned int text_width = log_rect.width / PANGO_SCALE;
194
195 if (icon_width)
196 width += spacing_;
197
198=== modified file 'panel/PanelMenuView.cpp'
199--- panel/PanelMenuView.cpp 2012-07-09 11:21:08 +0000
200+++ panel/PanelMenuView.cpp 2012-07-30 17:43:18 +0000
201@@ -700,7 +700,6 @@
202 using namespace panel;
203 cairo_t* cr;
204 cairo_pattern_t* linpat;
205- const int fading_pixels = 35;
206 int x = MAIN_LEFT_PADDING + TITLE_PADDING + geo.x;
207 int y = geo.y;
208
209@@ -762,6 +761,7 @@
210 if (text_width > text_space)
211 {
212 int out_pixels = text_width - text_space;
213+ const int fading_pixels = 35;
214 int fading_width = out_pixels < fading_pixels ? out_pixels : fading_pixels;
215
216 cairo_push_group(cr);
217
218=== modified file 'plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp'
219--- plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp 2012-04-06 10:23:49 +0000
220+++ plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp 2012-07-30 17:43:18 +0000
221@@ -292,7 +292,7 @@
222 CompWindowVector::const_iterator cit = clientListStacking.begin();
223 CompWindowVector::const_iterator oit = mLastClientListStacking.begin();
224
225- for (; cit != clientListStacking.end(); cit++, oit++)
226+ for (; cit != clientListStacking.end(); ++cit, oit++)
227 {
228 /* All clients from this point onwards in cit are invalidated
229 * so splice the list to the end of the new client list
230
231=== modified file 'plugins/unitydialog/src/unitydialog.cpp'
232--- plugins/unitydialog/src/unitydialog.cpp 2012-06-18 02:57:23 +0000
233+++ plugins/unitydialog/src/unitydialog.cpp 2012-07-30 17:43:18 +0000
234@@ -367,7 +367,7 @@
235 continue;
236 }
237
238- it++;
239+ ++it;
240 }
241 }
242
243@@ -1383,7 +1383,6 @@
244 CompWindow::Geometry transientGeometry;
245 CompRegion transientPos, outputRegion, outsideArea, outsideRegion;
246 pos = getChildCenteredPositionForRect(mParent->serverBorderRect());
247- int hdirection, vdirection;
248
249 transientGeometry = CompWindow::Geometry(pos.x(),
250 pos.y(),
251@@ -1406,8 +1405,8 @@
252 int width;
253 int height;
254
255- hdirection = outsideArea.boundingRect().x() < 0 ? 1 : -1;
256- vdirection = outsideArea.boundingRect().y() < 0 ? 1 : -1;
257+ int hdirection = outsideArea.boundingRect().x() < 0 ? 1 : -1;
258+ int vdirection = outsideArea.boundingRect().y() < 0 ? 1 : -1;
259
260 width = outsideArea.boundingRect().width() >=
261 window->serverBorderRect().width() ? 0 :
262
263=== modified file 'plugins/unityshell/src/nux-layout-accessible.cpp'
264--- plugins/unityshell/src/nux-layout-accessible.cpp 2011-08-01 17:08:48 +0000
265+++ plugins/unityshell/src/nux-layout-accessible.cpp 2012-07-30 17:43:18 +0000
266@@ -203,7 +203,7 @@
267
268 element_list = layout->GetChildren();
269
270- for (it = element_list.begin(); it != element_list.end(); it++, result++)
271+ for (it = element_list.begin(); it != element_list.end(); ++it, result++)
272 {
273 current_area = *it;
274 if (current_area == area)
275
276=== modified file 'plugins/unityshell/src/unity-launcher-accessible.cpp'
277--- plugins/unityshell/src/unity-launcher-accessible.cpp 2012-06-18 02:57:23 +0000
278+++ plugins/unityshell/src/unity-launcher-accessible.cpp 2012-07-30 17:43:18 +0000
279@@ -441,7 +441,7 @@
280 if (launcher_model == NULL)
281 return;
282
283- for (it = launcher_model->begin(); it != launcher_model->end(); it++)
284+ for (it = launcher_model->begin(); it != launcher_model->end(); ++it)
285 {
286 child = dynamic_cast<nux::Object*>((*it).GetPointer());
287 child_accessible = unity_a11y_get_accessible(child);
288
289=== modified file 'plugins/unityshell/src/unity-switcher-accessible.cpp'
290--- plugins/unityshell/src/unity-switcher-accessible.cpp 2012-03-14 06:24:18 +0000
291+++ plugins/unityshell/src/unity-switcher-accessible.cpp 2012-07-30 17:43:18 +0000
292@@ -404,7 +404,7 @@
293 if (switcher_model == NULL)
294 return;
295
296- for (it = switcher_model->begin(); it != switcher_model->end(); it++)
297+ for (it = switcher_model->begin(); it != switcher_model->end(); ++it)
298 {
299 child = *it;
300 child_accessible = unity_launcher_icon_accessible_new(child.GetPointer());
301
302=== modified file 'plugins/unityshell/src/unityshell.cpp'
303--- plugins/unityshell/src/unityshell.cpp 2012-07-19 00:21:25 +0000
304+++ plugins/unityshell/src/unityshell.cpp 2012-07-30 17:43:18 +0000
305@@ -1211,7 +1211,7 @@
306 CompWindowList const& wins = screen->windows();
307 for ( CompWindowList::const_reverse_iterator r = wins.rbegin()
308 ; r != wins.rend()
309- ; r++
310+ ; ++r
311 )
312 {
313 CompWindow* w = *r;
314@@ -1309,10 +1309,9 @@
315 ::GLFramebufferObject *fbo,
316 unsigned int mask)
317 {
318- bool useFbo = false;
319-
320 if (doShellRepaint)
321 {
322+ bool useFbo = false;
323 oldFbo = fbo->bind ();
324 useFbo = fbo->checkStatus () && fbo->tex ();
325 if (!useFbo) {
326@@ -2166,10 +2165,9 @@
327 {
328 // Look to see if there is a keycode. If there is, then this isn't a
329 // modifier only keybinding.
330- int key_code = 0;
331 if (options[6].type() != CompOption::TypeUnset)
332 {
333- key_code = options[6].value().i();
334+ int key_code = options[6].value().i();
335 LOG_DEBUG(logger) << "HUD initiate key code: " << key_code;
336 // show it now, no timings or terminate needed.
337 return ShowHud();
338
339=== modified file 'unity-shared/BGHash.cpp'
340--- unity-shared/BGHash.cpp 2012-06-18 02:57:23 +0000
341+++ unity-shared/BGHash.cpp 2012-07-30 17:43:18 +0000
342@@ -155,7 +155,6 @@
343 colors[10] = nux::Color (0x1b134c);
344 colors[11] = nux::Color (0x2c0d46);
345
346- float closest_diff = 200.0f;
347 nux::Color chosen_color;
348 nux::color::HueSaturationValue base_hsv (base_color);
349
350@@ -168,6 +167,7 @@
351 }
352 else
353 {
354+ float closest_diff = 200.0f;
355 LOG_DEBUG (logger) << "got a colour image";
356 // full colour image
357 for (int i = 0; i < 11; i++)
358
359=== modified file 'unity-shared/DashStyle.cpp'
360--- unity-shared/DashStyle.cpp 2012-07-22 23:09:02 +0000
361+++ unity-shared/DashStyle.cpp 2012-07-30 17:43:18 +0000
362@@ -1648,7 +1648,6 @@
363 double height = h - (2.0 * garnish) - 1.0;
364
365 bool odd = true;
366- double radius = 7.0;
367
368 // draw the grid background
369 {
370@@ -1656,6 +1655,7 @@
371 cairo_move_to(cr, _align(x + width, odd), y);
372 if (curve_bottom)
373 {
374+ double radius = 7.0;
375 LOG_DEBUG(logger) << "curve: " << _align(x + width, odd) << " - " << _align(y + height - radius, odd);
376 // line to bottom-right corner
377 cairo_line_to(cr, _align(x + width, odd), _align(y + height - radius, odd));
378
379=== modified file 'unity-shared/IconRenderer.cpp'
380--- unity-shared/IconRenderer.cpp 2012-07-22 23:12:28 +0000
381+++ unity-shared/IconRenderer.cpp 2012-07-30 17:43:18 +0000
382@@ -250,7 +250,7 @@
383
384 std::list<RenderArg>::iterator it;
385 int i;
386- for (it = args.begin(), i = 0; it != args.end(); it++, i++)
387+ for (it = args.begin(), i = 0; it != args.end(); ++it, i++)
388 {
389
390 IconTextureSource* launcher_icon = it->icon;
391@@ -757,7 +757,6 @@
392 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
393 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
394
395- int TextureObjectLocation;
396 int VertexLocation;
397 int TextureCoord0Location;
398 int FragmentColor = 0;
399@@ -768,7 +767,7 @@
400 {
401 local::shader_program_uv_persp_correction->Begin();
402
403- TextureObjectLocation = local::shader_program_uv_persp_correction->GetUniformLocationARB("TextureObject0");
404+ int TextureObjectLocation = local::shader_program_uv_persp_correction->GetUniformLocationARB("TextureObject0");
405 VertexLocation = local::shader_program_uv_persp_correction->GetAttributeLocation("iVertex");
406 TextureCoord0Location = local::shader_program_uv_persp_correction->GetAttributeLocation("iTexCoord0");
407 FragmentColor = local::shader_program_uv_persp_correction->GetUniformLocationARB("color0");
408
409=== modified file 'unity-shared/PluginAdapterCompiz.cpp'
410--- unity-shared/PluginAdapterCompiz.cpp 2012-07-04 02:37:23 +0000
411+++ unity-shared/PluginAdapterCompiz.cpp 2012-07-30 17:43:18 +0000
412@@ -1010,7 +1010,7 @@
413 }
414 else
415 {
416- for (it = window_list.begin(); it != window_list.end(); it++)
417+ for (it = window_list.begin(); it != window_list.end(); ++it)
418 {
419 if (CheckWindowIntersection(region, *it))
420 {