Merge lp:~sil2100/compiz-core/cherry_3243 into lp:compiz-core

Proposed by Łukasz Zemczak on 2012-06-21
Status: Merged
Approved by: Łukasz Zemczak on 2012-06-22
Approved revision: 3105
Merged at revision: 3109
Proposed branch: lp:~sil2100/compiz-core/cherry_3243
Merge into: lp:compiz-core
Diff against target: 319 lines (+97/-54)
5 files modified
src/main.cpp (+0/-8)
src/privatescreen.h (+22/-2)
src/privatestackdebugger.h (+9/-4)
src/screen.cpp (+36/-29)
src/stackdebugger.cpp (+30/-11)
To merge this branch: bzr merge lp:~sil2100/compiz-core/cherry_3243
Reviewer Review Type Date Requested Status
Daniel van Vugt 2012-06-21 Approve on 2012-06-22
Review via email: mp+111428@code.launchpad.net

Commit message

Cherry-picked from compiz trunk (rev 3243):
Avoid needless STL operations leading to expensive heap operations.
(LP: #1006335)

Description of the change

Original description:

Fixes needless list copying in event queues

To post a comment you must log in.
Daniel van Vugt (vanvugt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main.cpp'
2--- src/main.cpp 2012-03-08 12:37:21 +0000
3+++ src/main.cpp 2012-06-21 15:42:25 +0000
4@@ -172,14 +172,6 @@
5 screen->priv->setDirtyPluginList ();
6 screen->priv->updatePlugins ();
7
8- if (debugOutput)
9- {
10- StackDebugger::SetDefault (new StackDebugger (screen->dpy (),
11- screen->root (),
12- boost::bind (&PrivateScreen::queueEvents,
13- screen->priv.get())));
14- }
15-
16 if (!disableSm)
17 {
18 if (clientId == NULL)
19
20=== modified file 'src/privatescreen.h'
21--- src/privatescreen.h 2012-04-04 03:11:55 +0000
22+++ src/privatescreen.h 2012-06-21 15:42:25 +0000
23@@ -788,6 +788,23 @@
24
25 }} // namespace compiz::private_screen
26
27+class FetchXEventInterface
28+{
29+ public:
30+
31+ virtual ~FetchXEventInterface () {}
32+
33+ virtual bool getNextXEvent (XEvent &) = 0;
34+};
35+
36+class FetchEventInterface
37+{
38+ public:
39+
40+ virtual ~FetchEventInterface () {}
41+ virtual bool getNextEvent (XEvent &) = 0;
42+};
43+
44 class PrivateScreen :
45 public compiz::private_screen::EventManager,
46 public compiz::private_screen::WindowManager,
47@@ -795,7 +812,9 @@
48 public compiz::private_screen::History,
49 public compiz::private_screen::StartupSequence,
50 public compiz::private_screen::OrphanData,
51- public compiz::private_screen::PseudoNamespace
52+ public compiz::private_screen::PseudoNamespace,
53+ public FetchXEventInterface,
54+ public FetchEventInterface
55 {
56
57 public:
58@@ -804,7 +823,8 @@
59
60 bool setOption (const CompString &name, CompOption::Value &value);
61
62- std::list <XEvent> queueEvents ();
63+ bool getNextEvent (XEvent &);
64+ bool getNextXEvent (XEvent &);
65 void processEvents ();
66
67 bool triggerButtonPressBindings (CompOption::Vector &options,
68
69=== modified file 'src/privatestackdebugger.h'
70--- src/privatestackdebugger.h 2011-09-29 03:29:41 +0000
71+++ src/privatestackdebugger.h 2012-06-21 15:42:25 +0000
72@@ -27,20 +27,23 @@
73 * so that this can be come a truly standalone
74 * object */
75 #include <core/core.h>
76+#include <list>
77
78 #ifndef _COMPIZ_PRIVATESTACKDEBUGGER_H
79 #define _COMPIZ_PRIVATESTACKDEBUGGER_H
80
81+class FetchXEventInterface;
82+
83 class StackDebugger
84 {
85 public:
86
87- typedef std::list<XEvent> eventList;
88+ typedef std::vector<XEvent> eventList;
89
90- StackDebugger (Display *, Window, boost::function<eventList ()> evProc);
91+ StackDebugger (Display *, Window, FetchXEventInterface *fetchXEvent);
92 ~StackDebugger ();
93
94- eventList loadStack (CompWindowList &serverWindows, bool wait = false);
95+ void loadStack (CompWindowList &serverWindows, bool wait = false);
96 void windowsChanged (bool change) { mWindowsChanged = change; };
97 void serverWindowsChanged (bool change) { mServerWindowsChanged = change; };
98 bool windowsChanged () { return mWindowsChanged; }
99@@ -54,6 +57,7 @@
100 CompWindowList &serverWindows,
101 bool verbose = false);
102 bool timedOut ();
103+ bool getNextEvent (XEvent &);
104
105 bool checkSanity (CompWindowList &serverWindows, bool verbose = false);
106
107@@ -70,9 +74,10 @@
108 bool mServerWindowsChanged;
109 Window mRoot;
110 Display *mDpy;
111- boost::function<eventList ()> getEventsProc;
112+ FetchXEventInterface *mFetchXEvent;
113 bool mTimeoutRequired;
114 CompWindowList mLastServerWindows;
115+ std::list <XEvent> mEvents;
116 };
117
118 #endif
119
120=== modified file 'src/screen.cpp'
121--- src/screen.cpp 2012-03-30 06:26:33 +0000
122+++ src/screen.cpp 2012-06-21 15:42:25 +0000
123@@ -742,41 +742,48 @@
124 return rv;
125 }
126
127-std::list <XEvent>
128-PrivateScreen::queueEvents ()
129+bool
130+PrivateScreen::getNextXEvent (XEvent &ev)
131 {
132- std::list <XEvent> events;
133+ if (!XEventsQueued (dpy, QueuedAlready))
134+ return false;
135+ XNextEvent (dpy, &ev);
136
137- while (XPending (dpy))
138+ /* Skip to the last MotionNotify
139+ * event in this sequence */
140+ if (ev.type == MotionNotify)
141 {
142- XEvent event, peekEvent;
143- XNextEvent (dpy, &event);
144-
145- /* Skip to the last MotionNotify
146- * event in this sequence */
147- if (event.type == MotionNotify)
148+ XEvent peekEvent;
149+ while (XPending (dpy))
150 {
151- while (XPending (dpy))
152- {
153- XPeekEvent (dpy, &peekEvent);
154-
155- if (peekEvent.type != MotionNotify)
156- break;
157-
158- XNextEvent (dpy, &event);
159- }
160+ XPeekEvent (dpy, &peekEvent);
161+
162+ if (peekEvent.type != MotionNotify)
163+ break;
164+
165+ XNextEvent (dpy, &peekEvent);
166 }
167-
168- events.push_back (event);
169- }
170-
171- return events;
172+ }
173+
174+ return true;
175+}
176+
177+bool
178+PrivateScreen::getNextEvent (XEvent &ev)
179+{
180+ StackDebugger *dbg = StackDebugger::Default ();
181+
182+ if (StackDebugger::Default ())
183+ {
184+ return dbg->getNextEvent (ev);
185+ }
186+ else
187+ return getNextXEvent (ev);
188 }
189
190 void
191 PrivateScreen::processEvents ()
192 {
193- std::list <XEvent> events;
194 StackDebugger *dbg = StackDebugger::Default ();
195
196 if (isDirtyPluginList ())
197@@ -801,14 +808,14 @@
198 {
199 dbg->windowsChanged (false);
200 dbg->serverWindowsChanged (false);
201- events = dbg->loadStack (serverWindows);
202+ dbg->loadStack (serverWindows);
203 }
204- else
205- events = queueEvents ();
206
207 stackIsFresh = false;
208
209- foreach (XEvent &event, events)
210+ XEvent event;
211+
212+ while (getNextEvent (event))
213 {
214 switch (event.type) {
215 case ButtonPress:
216
217=== modified file 'src/stackdebugger.cpp'
218--- src/stackdebugger.cpp 2011-10-07 11:45:38 +0000
219+++ src/stackdebugger.cpp 2012-06-21 15:42:25 +0000
220@@ -24,6 +24,7 @@
221 */
222
223 #include "privatestackdebugger.h"
224+#include "privatescreen.h"
225 #include "privatewindow.h"
226 #include <poll.h>
227
228@@ -47,14 +48,14 @@
229 gStackDebugger = dbg;
230 }
231
232-StackDebugger::StackDebugger (Display *dpy, Window root, boost::function <eventList ()> evProc) :
233+StackDebugger::StackDebugger (Display *dpy, Window root, FetchXEventInterface *fetchXEvent) :
234 mServerNChildren (0),
235 mServerChildren (NULL),
236 mWindowsChanged (false),
237 mServerWindowsChanged (false),
238 mRoot (root),
239 mDpy (dpy),
240- getEventsProc (evProc)
241+ mFetchXEvent (fetchXEvent)
242 {
243 }
244
245@@ -118,11 +119,23 @@
246 mLastServerWindows.push_front (tl);
247 }
248
249-StackDebugger::eventList
250+bool
251+StackDebugger::getNextEvent (XEvent &ev)
252+{
253+ if (mEvents.empty ())
254+ return false;
255+
256+ ev = mEvents.front ();
257+
258+ mEvents.pop_front ();
259+
260+ return true;
261+}
262+
263+void
264 StackDebugger::loadStack (CompWindowList &serverWindows, bool wait)
265 {
266 Window rootRet, parentRet;
267- eventList events;
268
269 if (mServerChildren)
270 XFree (mServerChildren);
271@@ -132,7 +145,16 @@
272 XQueryTree (mDpy, mRoot, &rootRet, &parentRet,
273 &mServerChildren, &mServerNChildren);
274
275- events = getEventsProc ();
276+ unsigned int n = XEventsQueued (mDpy, QueuedAfterFlush);
277+ mEvents.clear ();
278+ mEvents.resize (n);
279+ std::list <XEvent>::iterator it = mEvents.begin ();
280+
281+ while (it != mEvents.end ())
282+ {
283+ mFetchXEvent->getNextXEvent ((*it));
284+ it++;
285+ }
286
287 XSync (mDpy, FALSE);
288
289@@ -145,7 +167,6 @@
290
291 if (mServerNChildren != serverWindows.size () && wait)
292 {
293- eventList moreEvents;
294 struct pollfd pfd;
295
296 pfd.events = POLLIN;
297@@ -154,10 +175,10 @@
298
299 poll (&pfd, 1, 300);
300
301- moreEvents = getEventsProc ();
302+ XEvent e;
303
304- foreach (XEvent e, moreEvents)
305- events.push_back (e);
306+ while (mFetchXEvent->getNextXEvent (e))
307+ mEvents.push_back (e);
308
309 mTimeoutRequired = true;
310 }
311@@ -166,8 +187,6 @@
312
313 XUngrabServer (mDpy);
314 XSync (mDpy, FALSE);
315-
316- return events;
317 }
318
319 void

Subscribers

People subscribed via source and target branches