Merge lp:~ricotz/appcenter/optimizations into lp:~elementary-apps/appcenter/appcenter

Proposed by Rico Tzschichholz
Status: Work in progress
Proposed branch: lp:~ricotz/appcenter/optimizations
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 180 lines (+29/-26)
5 files modified
src/Core/ChangeInformation.vala (+1/-1)
src/Core/Client.vala (+3/-3)
src/Core/Package.vala (+19/-16)
src/Views/FeaturedView.vala (+4/-4)
src/Widgets/AppCellRenderer.vala (+2/-2)
To merge this branch: bzr merge lp:~ricotz/appcenter/optimizations
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+309377@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

330. By Rico Tzschichholz

Retrieve matching Pk.Package only once when required

329. By Rico Tzschichholz

Avoid a bunch of string copying

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Core/ChangeInformation.vala'
2--- src/Core/ChangeInformation.vala 2016-10-07 17:44:50 +0000
3+++ src/Core/ChangeInformation.vala 2016-10-26 18:22:34 +0000
4@@ -48,7 +48,7 @@
5 return changes.size > 0;
6 }
7
8- public string get_status_string () {
9+ public unowned string get_status_string () {
10 switch (status) {
11 case Pk.Status.SETUP:
12 return _("Starting");
13
14=== modified file 'src/Core/Client.vala'
15--- src/Core/Client.vala 2016-10-26 12:59:05 +0000
16+++ src/Core/Client.vala 2016-10-26 18:22:34 +0000
17@@ -38,7 +38,7 @@
18 private Client () {
19 appstream_pool.get_components ().foreach ((comp) => {
20 var package = new AppCenterCore.Package (comp);
21- foreach (var pkg_name in comp.get_pkgnames ()) {
22+ foreach (unowned string pkg_name in comp.get_pkgnames ()) {
23 package_list.set (pkg_name, package);
24 }
25 });
26@@ -103,7 +103,7 @@
27 AppCenter.Task install_task = request_task ();
28 AppCenter.Task search_task = request_task ();
29 string[] packages_ids = {};
30- foreach (var pkg_name in package.component.get_pkgnames ()) {
31+ foreach (unowned string pkg_name in package.component.get_pkgnames ()) {
32 packages_ids += pkg_name;
33 }
34
35@@ -175,7 +175,7 @@
36 AppCenter.Task remove_task = request_task ();
37 AppCenter.Task search_task = request_task ();
38 string[] packages_ids = {};
39- foreach (var pkg_name in package.component.get_pkgnames ()) {
40+ foreach (unowned string pkg_name in package.component.get_pkgnames ()) {
41 packages_ids += pkg_name;
42 }
43 packages_ids += null;
44
45=== modified file 'src/Core/Package.vala'
46--- src/Core/Package.vala 2016-09-14 16:58:13 +0000
47+++ src/Core/Package.vala 2016-10-26 18:22:34 +0000
48@@ -39,6 +39,9 @@
49 public GLib.Cancellable action_cancellable { public get; private set; }
50 public State state { public get; private set; default = State.NOT_INSTALLED; }
51
52+ private Pk.Package? package = null;
53+ private bool package_retrieved = false;
54+
55 public double progress {
56 get {
57 return change_information.progress;
58@@ -183,13 +186,13 @@
59 }
60 }
61
62- public string? get_name () {
63- var _name = component.get_name ();
64+ public unowned string? get_name () {
65+ unowned string _name = component.get_name ();
66 if (_name != null) {
67 return _name;
68 }
69
70- var package = find_package ();
71+ unowned Pk.Package? package = find_package ();
72 if (package != null) {
73 return package.get_name ();
74 }
75@@ -197,13 +200,13 @@
76 return null;
77 }
78
79- public string? get_summary () {
80- var summary = component.get_summary ();
81+ public unowned string? get_summary () {
82+ unowned string summary = component.get_summary ();
83 if (summary != null) {
84 return summary;
85 }
86
87- var package = find_package ();
88+ unowned Pk.Package? package = find_package ();
89 if (package != null) {
90 return package.get_summary ();
91 }
92@@ -211,7 +214,7 @@
93 return null;
94 }
95
96- public string get_progress_description () {
97+ public unowned string get_progress_description () {
98 return change_information.get_status_string ();
99 }
100
101@@ -265,7 +268,7 @@
102 }
103
104 public string? get_version () {
105- var package = find_package ();
106+ unowned Pk.Package? package = find_package ();
107 if (package != null) {
108 string returned = package.get_version ();
109 returned = returned.split ("+", 2)[0];
110@@ -281,21 +284,21 @@
111 return null;
112 }
113
114- private Pk.Package? find_package (bool installed = false) {
115+ private unowned Pk.Package? find_package () {
116 if (component.id == OS_UPDATES_ID) {
117 return null;
118 }
119
120+ if (package_retrieved)
121+ return package;
122+
123 try {
124- Pk.Bitfield filter = 0;
125- if (installed) {
126- filter = Pk.Bitfield.from_enums (Pk.Filter.INSTALLED);
127- }
128-
129- return AppCenterCore.Client.get_default ().get_app_package (component.get_pkgnames ()[0], filter);
130+ package = AppCenterCore.Client.get_default ().get_app_package (component.get_pkgnames ()[0], 0LL);
131 } catch (Error e) {
132 critical (e.message);
133- return null;
134 }
135+
136+ package_retrieved = true;
137+ return package;
138 }
139 }
140
141=== modified file 'src/Views/FeaturedView.vala'
142--- src/Views/FeaturedView.vala 2015-10-30 17:53:09 +0000
143+++ src/Views/FeaturedView.vala 2016-10-26 18:22:34 +0000
144@@ -46,8 +46,8 @@
145 Gdk.RGBA background_color = {0, 0, 0, 1};
146 background_color.parse ("#3689e6");
147 Gdk.RGBA text_color = {1, 1, 1, 1};
148- string title = "Apport";
149- string subtitle = "Crash Reporting Tool";
150+ unowned string title = "Apport";
151+ unowned string subtitle = "Crash Reporting Tool";
152 var icon = new ThemedIcon ("apport");
153 var left_placeholder = new Widgets.FeaturedButton (background_color, text_color, title, subtitle, icon);
154 return left_placeholder;
155@@ -57,8 +57,8 @@
156 Gdk.RGBA background_color = {0, 0, 0, 1};
157 background_color.parse ("#999999");
158 Gdk.RGBA text_color = {1, 1, 1, 1};
159- string title = "Database";
160- string subtitle = "It's grown up and professional";
161+ unowned string title = "Database";
162+ unowned string subtitle = "It's grown up and professional";
163 var icon = new ThemedIcon ("office-database");
164 var left_placeholder = new Widgets.FeaturedButton (background_color, text_color, title, subtitle, icon);
165 return left_placeholder;
166
167=== modified file 'src/Widgets/AppCellRenderer.vala'
168--- src/Widgets/AppCellRenderer.vala 2015-11-17 18:35:04 +0000
169+++ src/Widgets/AppCellRenderer.vala 2016-10-26 18:22:34 +0000
170@@ -57,8 +57,8 @@
171
172 /* render method */
173 public override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
174- var title = package.get_name ();
175- var summary = package.get_summary ();
176+ unowned string title = package.get_name ();
177+ unowned string summary = package.get_summary ();
178
179 int x = background_area.x;
180 int y = background_area.y + MARGIN;

Subscribers

People subscribed via source and target branches