Merge lp:~3v1n0/bamf/cache-exec-string into lp:bamf

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: 624
Merged at revision: 568
Proposed branch: lp:~3v1n0/bamf/cache-exec-string
Merge into: lp:bamf
Prerequisite: lp:~3v1n0/bamf/qmlapp-matching
Diff against target: 170 lines (+23/-18)
5 files modified
src/bamf-application.c (+1/-2)
src/bamf-legacy-window-test.c (+2/-2)
src/bamf-legacy-window.c (+15/-6)
src/bamf-legacy-window.h (+2/-2)
src/bamf-matcher.c (+3/-6)
To merge this branch: bzr merge lp:~3v1n0/bamf/cache-exec-string
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+176540@code.launchpad.net

Commit message

BamfLegacyWindow: cache the window Exec string

We might use this value multiple times during the BAMF execution,
and we don't need to recompute it everytime. Caching looks a good compromise.

Description of the change

Caching the window exec-string, as w might use this value multiple times during the BAMF execution and we don't need to recompute it everytime. Caching looks a good compromise.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Nice. LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-application.c'
2--- src/bamf-application.c 2013-07-23 22:47:22 +0000
3+++ src/bamf-application.c 2013-07-23 22:47:22 +0000
4@@ -319,9 +319,8 @@
5
6 if (!icon)
7 {
8- char *exec = bamf_legacy_window_get_exec_string (legacy_window);
9+ const char *exec = bamf_legacy_window_get_exec_string (legacy_window);
10 icon = bamf_matcher_get_trimmed_exec (bamf_matcher_get_default (), exec);
11- g_free (exec);
12
13 if (icon_name_is_valid (icon))
14 {
15
16=== modified file 'src/bamf-legacy-window-test.c'
17--- src/bamf-legacy-window-test.c 2013-06-21 14:38:53 +0000
18+++ src/bamf-legacy-window-test.c 2013-07-23 22:47:22 +0000
19@@ -231,14 +231,14 @@
20 return self->wm_class_instance;
21 }
22
23-char *
24+const char *
25 bamf_legacy_window_test_get_exec_string (BamfLegacyWindow *legacy_window)
26 {
27 BamfLegacyWindowTest *self;
28
29 self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
30
31- return g_strdup (self->exec);
32+ return self->exec;
33 }
34
35 char *
36
37=== modified file 'src/bamf-legacy-window.c'
38--- src/bamf-legacy-window.c 2013-06-21 14:38:29 +0000
39+++ src/bamf-legacy-window.c 2013-07-23 22:47:22 +0000
40@@ -51,7 +51,8 @@
41 struct _BamfLegacyWindowPrivate
42 {
43 WnckWindow * legacy_window;
44- char * mini_icon_path;
45+ gchar * mini_icon_path;
46+ gchar * exec_string;
47 gboolean is_closed;
48 };
49
50@@ -218,10 +219,9 @@
51 return result;
52 }
53
54-char *
55+const char *
56 bamf_legacy_window_get_exec_string (BamfLegacyWindow *self)
57 {
58- gchar *result = NULL;
59 gint pid = 0, i = 0;
60 gchar **argv = NULL;
61 GString *exec = NULL;
62@@ -232,6 +232,9 @@
63 if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_exec_string)
64 return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_exec_string (self);
65
66+ if (self->priv->exec_string)
67+ return self->priv->exec_string;
68+
69 pid = bamf_legacy_window_get_pid (self);
70
71 if (pid == 0)
72@@ -251,9 +254,10 @@
73
74 g_free (argv);
75
76- result = g_strdup (exec->str);
77+ self->priv->exec_string = g_strdup (exec->str);
78 g_string_free (exec, TRUE);
79- return result;
80+
81+ return self->priv->exec_string;
82 }
83
84 const char *
85@@ -564,7 +568,6 @@
86
87 self = BAMF_LEGACY_WINDOW (object);
88
89-
90 if (self->priv->mini_icon_path)
91 {
92 file = g_file_new_for_path (self->priv->mini_icon_path);
93@@ -575,6 +578,12 @@
94 self->priv->mini_icon_path = NULL;
95 }
96
97+ if (self->priv->exec_string)
98+ {
99+ g_free (self->priv->exec_string);
100+ self->priv->exec_string = NULL;
101+ }
102+
103 g_signal_handlers_disconnect_by_data (wnck_screen_get_default (), self);
104
105 if (self->priv->legacy_window)
106
107=== modified file 'src/bamf-legacy-window.h'
108--- src/bamf-legacy-window.h 2013-06-21 14:38:29 +0000
109+++ src/bamf-legacy-window.h 2013-07-23 22:47:22 +0000
110@@ -77,7 +77,7 @@
111 const char * (*get_class_name) (BamfLegacyWindow *legacy_window);
112 const char * (*get_class_instance_name) (BamfLegacyWindow *legacy_window);
113 const char * (*save_mini_icon) (BamfLegacyWindow *legacy_window);
114- char * (*get_exec_string) (BamfLegacyWindow *legacy_window);
115+ const char * (*get_exec_string) (BamfLegacyWindow *legacy_window);
116 char * (*get_process_name) (BamfLegacyWindow *legacy_window);
117 char * (*get_app_id) (BamfLegacyWindow *legacy_window);
118 char * (*get_unique_bus_name) (BamfLegacyWindow *legacy_window);
119@@ -149,7 +149,7 @@
120
121 const char * bamf_legacy_window_save_mini_icon (BamfLegacyWindow *self);
122
123-char * bamf_legacy_window_get_exec_string (BamfLegacyWindow *self);
124+const char * bamf_legacy_window_get_exec_string (BamfLegacyWindow *self);
125
126 char * bamf_legacy_window_get_process_name (BamfLegacyWindow *self);
127
128
129=== modified file 'src/bamf-matcher.c'
130--- src/bamf-matcher.c 2013-07-23 22:47:22 +0000
131+++ src/bamf-matcher.c 2013-07-23 22:47:22 +0000
132@@ -1350,7 +1350,7 @@
133 {
134 BamfMatcherPrivate *priv;
135 GList *result = NULL, *table_list, *l;
136- char *exec_string;
137+ const char *exec_string;
138 char *trimmed;
139
140 g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
141@@ -1376,7 +1376,6 @@
142 }
143 g_free (trimmed);
144 }
145- g_free (exec_string);
146 }
147
148 if (result)
149@@ -1794,9 +1793,8 @@
150 const gchar *app_desktop_class;
151
152 const char *win_instance_name = bamf_legacy_window_get_class_instance_name (window);
153- char *exec_string = bamf_legacy_window_get_exec_string (window);
154+ const char *exec_string = bamf_legacy_window_get_exec_string (window);
155 char *trimmed_exec = bamf_matcher_get_trimmed_exec (self, exec_string);
156- g_free (exec_string);
157
158 if (trimmed_exec || win_class_name || win_instance_name)
159 {
160@@ -1819,9 +1817,8 @@
161 continue;
162
163 BamfLegacyWindow *w = bamf_window_get_window (BAMF_WINDOW (ll->data));
164- char *wexec = bamf_legacy_window_get_exec_string (w);
165+ const char *wexec = bamf_legacy_window_get_exec_string (w);
166 char *wtrimmed = bamf_matcher_get_trimmed_exec (self, wexec);
167- g_free (wexec);
168
169 if (g_strcmp0 (trimmed_exec, wtrimmed) == 0)
170 {

Subscribers

People subscribed via source and target branches