Merge lp:~mc-return/unity/unity.merge-more-optimizing into lp:unity

Proposed by MC Return on 2012-08-05
Status: Merged
Approved by: Tim Penhey on 2012-08-17
Approved revision: 2549
Merged at revision: 2580
Proposed branch: lp:~mc-return/unity/unity.merge-more-optimizing
Merge into: lp:unity
Diff against target: 67 lines (+5/-11)
3 files modified
UnityCore/Indicator.cpp (+1/-7)
dash/ResultViewGrid.cpp (+0/-1)
unity-shared/PluginAdapterCompiz.cpp (+4/-3)
To merge this branch: bzr merge lp:~mc-return/unity/unity.merge-more-optimizing
Reviewer Review Type Date Requested Status
Tim Penhey (community) 2012-08-05 Approve on 2012-08-17
MC Return (community) Resubmit on 2012-08-08
Review via email: mp+118265@code.launchpad.net

Commit Message

Minor optimizations:

Used 'if (entries_.empty())' instead of 'if (entries_.size() == 0) because it can be faster. xxxx.size() can take linear time while xxxx.empty() is guaranteed to take constant time.

Replaced 'windows.size() > 0' with '!windows.empty()' and '!m_ActionList.size()' with 'm_ActionList.empty()' (x2) in PluginAdapterCompiz.cpp to optimize performance.

Simplified void Indicator::Sync(Indicator::Entries const& new_entries) by removing the assignment of an empty list into an empty list and just using if (!entries_.empty()) instead of the else condition.

Removed redundant parentheses.

Introduced std::size_t num_windows = windows.size(); and changed the if statement in PluginAdapter::ScaleWindowGroup to check num_windows.

Removed declaration of the unused variable 'next_focused_uri'.

Description of the Change

Various optimizations.

To post a comment you must log in.
MC Return (mc-return) wrote :

Please especially check r2543. I am not entirely sure if this commit is correct.

Tim Penhey (thumper) wrote :

I know you just changed the logic in UnityCore/Indicator.cpp, but the code isn't needed, so delete the block where we are assigning an empty list into an empty list, and just use
  if (!entries_.empty())
instead of the else condition.

In PluginAdapter::ScaleWindowGroup we are already caring about the size, so get it once before the if statement.

  std::size_t num_windows = windows.size();
  if (num_windows > 1 || (force && num_windows))

review: Needs Fixing
MC Return (mc-return) wrote :

> I know you just changed the logic in UnityCore/Indicator.cpp, but the code
> isn't needed, so delete the block where we are assigning an empty list into an
> empty list, and just use
> if (!entries_.empty())
> instead of the else condition.

Fixed. Also removed redundant parentheses.

> In PluginAdapter::ScaleWindowGroup we are already caring about the size, so
> get it once before the if statement.
>
> std::size_t num_windows = windows.size();
> if (num_windows > 1 || (force && num_windows))

Done.

MC Return (mc-return) :
review: Resubmit
Tim Penhey (thumper) :
review: Approve
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1060/console reported an error when processing this lp:~mc-return/unity/unity.merge-more-optimizing branch.
Not merging it.

2548. By MC Return on 2012-08-17

Merged lp:unity

2549. By MC Return on 2012-08-17

Fixed compilation by reverting r2543

Tim Penhey (thumper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/Indicator.cpp'
2--- UnityCore/Indicator.cpp 2012-06-18 02:57:23 +0000
3+++ UnityCore/Indicator.cpp 2012-08-17 06:20:24 +0000
4@@ -64,18 +64,12 @@
5 {
6 Entries to_rm;
7
8- if (entries_.size() == 0)
9- {
10- to_rm = entries_;
11- }
12- else
13+ if (!entries_.empty())
14 {
15 for (auto entry : entries_)
16 {
17 if (std::find(new_entries.begin(), new_entries.end(), entry) == new_entries.end())
18- {
19 to_rm.push_back(entry);
20- }
21 }
22 }
23
24
25=== modified file 'dash/ResultViewGrid.cpp'
26--- dash/ResultViewGrid.cpp 2012-08-15 09:54:22 +0000
27+++ dash/ResultViewGrid.cpp 2012-08-17 06:20:24 +0000
28@@ -404,7 +404,6 @@
29 if (focused_uri_.empty())
30 focused_uri_ = results_.front().uri;
31
32- std::string next_focused_uri;
33 ResultList::iterator it;
34 int items_per_row = GetItemsPerRow();
35 int total_rows = std::ceil(results_.size() / static_cast<float>(items_per_row)); // items per row is always at least 1
36
37=== modified file 'unity-shared/PluginAdapterCompiz.cpp'
38--- unity-shared/PluginAdapterCompiz.cpp 2012-08-10 22:55:17 +0000
39+++ unity-shared/PluginAdapterCompiz.cpp 2012-08-17 06:20:24 +0000
40@@ -242,7 +242,7 @@
41 MultiActionList::InitiateAll(CompOption::Vector& extraArgs, int state)
42 {
43 CompOption::Vector argument;
44- if (!m_ActionList.size())
45+ if (m_ActionList.empty())
46 return;
47
48 argument.resize(1);
49@@ -269,7 +269,7 @@
50 {
51 CompOption::Vector argument;
52 CompOption::Value value;
53- if (!m_ActionList.size())
54+ if (m_ActionList.empty())
55 return;
56
57 argument.resize(1);
58@@ -821,7 +821,8 @@
59 bool
60 PluginAdapter::ScaleWindowGroup(std::vector<Window> windows, int state, bool force)
61 {
62- if (windows.size() > 1 || (force && windows.size() > 0))
63+ std::size_t num_windows = windows.size();
64+ if (num_windows > 1 || (force && num_windows))
65 {
66 std::string match = MatchStringForXids(&windows);
67 InitiateScale(match, state);