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

Proposed by Łukasz Zemczak
Status: Merged
Approved by: Łukasz Zemczak
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 Approve
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.
Revision history for this message
Daniel van Vugt (vanvugt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/main.cpp'
--- src/main.cpp 2012-03-08 12:37:21 +0000
+++ src/main.cpp 2012-06-21 15:42:25 +0000
@@ -172,14 +172,6 @@
172 screen->priv->setDirtyPluginList ();172 screen->priv->setDirtyPluginList ();
173 screen->priv->updatePlugins ();173 screen->priv->updatePlugins ();
174174
175 if (debugOutput)
176 {
177 StackDebugger::SetDefault (new StackDebugger (screen->dpy (),
178 screen->root (),
179 boost::bind (&PrivateScreen::queueEvents,
180 screen->priv.get())));
181 }
182
183 if (!disableSm)175 if (!disableSm)
184 {176 {
185 if (clientId == NULL)177 if (clientId == NULL)
186178
=== modified file 'src/privatescreen.h'
--- src/privatescreen.h 2012-04-04 03:11:55 +0000
+++ src/privatescreen.h 2012-06-21 15:42:25 +0000
@@ -788,6 +788,23 @@
788788
789}} // namespace compiz::private_screen789}} // namespace compiz::private_screen
790790
791class FetchXEventInterface
792{
793 public:
794
795 virtual ~FetchXEventInterface () {}
796
797 virtual bool getNextXEvent (XEvent &) = 0;
798};
799
800class FetchEventInterface
801{
802 public:
803
804 virtual ~FetchEventInterface () {}
805 virtual bool getNextEvent (XEvent &) = 0;
806};
807
791class PrivateScreen :808class PrivateScreen :
792 public compiz::private_screen::EventManager,809 public compiz::private_screen::EventManager,
793 public compiz::private_screen::WindowManager,810 public compiz::private_screen::WindowManager,
@@ -795,7 +812,9 @@
795 public compiz::private_screen::History,812 public compiz::private_screen::History,
796 public compiz::private_screen::StartupSequence,813 public compiz::private_screen::StartupSequence,
797 public compiz::private_screen::OrphanData,814 public compiz::private_screen::OrphanData,
798 public compiz::private_screen::PseudoNamespace815 public compiz::private_screen::PseudoNamespace,
816 public FetchXEventInterface,
817 public FetchEventInterface
799{818{
800819
801 public:820 public:
@@ -804,7 +823,8 @@
804823
805 bool setOption (const CompString &name, CompOption::Value &value);824 bool setOption (const CompString &name, CompOption::Value &value);
806825
807 std::list <XEvent> queueEvents ();826 bool getNextEvent (XEvent &);
827 bool getNextXEvent (XEvent &);
808 void processEvents ();828 void processEvents ();
809829
810 bool triggerButtonPressBindings (CompOption::Vector &options,830 bool triggerButtonPressBindings (CompOption::Vector &options,
811831
=== modified file 'src/privatestackdebugger.h'
--- src/privatestackdebugger.h 2011-09-29 03:29:41 +0000
+++ src/privatestackdebugger.h 2012-06-21 15:42:25 +0000
@@ -27,20 +27,23 @@
27 * so that this can be come a truly standalone27 * so that this can be come a truly standalone
28 * object */28 * object */
29#include <core/core.h>29#include <core/core.h>
30#include <list>
3031
31#ifndef _COMPIZ_PRIVATESTACKDEBUGGER_H32#ifndef _COMPIZ_PRIVATESTACKDEBUGGER_H
32#define _COMPIZ_PRIVATESTACKDEBUGGER_H33#define _COMPIZ_PRIVATESTACKDEBUGGER_H
3334
35class FetchXEventInterface;
36
34class StackDebugger37class StackDebugger
35{38{
36 public:39 public:
3740
38 typedef std::list<XEvent> eventList;41 typedef std::vector<XEvent> eventList;
3942
40 StackDebugger (Display *, Window, boost::function<eventList ()> evProc);43 StackDebugger (Display *, Window, FetchXEventInterface *fetchXEvent);
41 ~StackDebugger ();44 ~StackDebugger ();
4245
43 eventList loadStack (CompWindowList &serverWindows, bool wait = false);46 void loadStack (CompWindowList &serverWindows, bool wait = false);
44 void windowsChanged (bool change) { mWindowsChanged = change; };47 void windowsChanged (bool change) { mWindowsChanged = change; };
45 void serverWindowsChanged (bool change) { mServerWindowsChanged = change; };48 void serverWindowsChanged (bool change) { mServerWindowsChanged = change; };
46 bool windowsChanged () { return mWindowsChanged; }49 bool windowsChanged () { return mWindowsChanged; }
@@ -54,6 +57,7 @@
54 CompWindowList &serverWindows,57 CompWindowList &serverWindows,
55 bool verbose = false);58 bool verbose = false);
56 bool timedOut ();59 bool timedOut ();
60 bool getNextEvent (XEvent &);
5761
58 bool checkSanity (CompWindowList &serverWindows, bool verbose = false);62 bool checkSanity (CompWindowList &serverWindows, bool verbose = false);
5963
@@ -70,9 +74,10 @@
70 bool mServerWindowsChanged;74 bool mServerWindowsChanged;
71 Window mRoot;75 Window mRoot;
72 Display *mDpy;76 Display *mDpy;
73 boost::function<eventList ()> getEventsProc;77 FetchXEventInterface *mFetchXEvent;
74 bool mTimeoutRequired;78 bool mTimeoutRequired;
75 CompWindowList mLastServerWindows;79 CompWindowList mLastServerWindows;
80 std::list <XEvent> mEvents;
76};81};
7782
78#endif83#endif
7984
=== modified file 'src/screen.cpp'
--- src/screen.cpp 2012-03-30 06:26:33 +0000
+++ src/screen.cpp 2012-06-21 15:42:25 +0000
@@ -742,41 +742,48 @@
742 return rv;742 return rv;
743}743}
744744
745std::list <XEvent>745bool
746PrivateScreen::queueEvents ()746PrivateScreen::getNextXEvent (XEvent &ev)
747{747{
748 std::list <XEvent> events;748 if (!XEventsQueued (dpy, QueuedAlready))
749 return false;
750 XNextEvent (dpy, &ev);
749751
750 while (XPending (dpy))752 /* Skip to the last MotionNotify
753 * event in this sequence */
754 if (ev.type == MotionNotify)
751 {755 {
752 XEvent event, peekEvent;756 XEvent peekEvent;
753 XNextEvent (dpy, &event);757 while (XPending (dpy))
754
755 /* Skip to the last MotionNotify
756 * event in this sequence */
757 if (event.type == MotionNotify)
758 {758 {
759 while (XPending (dpy))759 XPeekEvent (dpy, &peekEvent);
760 {760
761 XPeekEvent (dpy, &peekEvent);761 if (peekEvent.type != MotionNotify)
762762 break;
763 if (peekEvent.type != MotionNotify)763
764 break;764 XNextEvent (dpy, &peekEvent);
765
766 XNextEvent (dpy, &event);
767 }
768 }765 }
769766 }
770 events.push_back (event);767
771 }768 return true;
772769}
773 return events;770
771bool
772PrivateScreen::getNextEvent (XEvent &ev)
773{
774 StackDebugger *dbg = StackDebugger::Default ();
775
776 if (StackDebugger::Default ())
777 {
778 return dbg->getNextEvent (ev);
779 }
780 else
781 return getNextXEvent (ev);
774}782}
775783
776void784void
777PrivateScreen::processEvents ()785PrivateScreen::processEvents ()
778{786{
779 std::list <XEvent> events;
780 StackDebugger *dbg = StackDebugger::Default ();787 StackDebugger *dbg = StackDebugger::Default ();
781788
782 if (isDirtyPluginList ())789 if (isDirtyPluginList ())
@@ -801,14 +808,14 @@
801 {808 {
802 dbg->windowsChanged (false);809 dbg->windowsChanged (false);
803 dbg->serverWindowsChanged (false);810 dbg->serverWindowsChanged (false);
804 events = dbg->loadStack (serverWindows);811 dbg->loadStack (serverWindows);
805 }812 }
806 else
807 events = queueEvents ();
808813
809 stackIsFresh = false;814 stackIsFresh = false;
810815
811 foreach (XEvent &event, events)816 XEvent event;
817
818 while (getNextEvent (event))
812 {819 {
813 switch (event.type) {820 switch (event.type) {
814 case ButtonPress:821 case ButtonPress:
815822
=== modified file 'src/stackdebugger.cpp'
--- src/stackdebugger.cpp 2011-10-07 11:45:38 +0000
+++ src/stackdebugger.cpp 2012-06-21 15:42:25 +0000
@@ -24,6 +24,7 @@
24 */24 */
2525
26#include "privatestackdebugger.h"26#include "privatestackdebugger.h"
27#include "privatescreen.h"
27#include "privatewindow.h"28#include "privatewindow.h"
28#include <poll.h>29#include <poll.h>
2930
@@ -47,14 +48,14 @@
47 gStackDebugger = dbg;48 gStackDebugger = dbg;
48}49}
4950
50StackDebugger::StackDebugger (Display *dpy, Window root, boost::function <eventList ()> evProc) :51StackDebugger::StackDebugger (Display *dpy, Window root, FetchXEventInterface *fetchXEvent) :
51 mServerNChildren (0),52 mServerNChildren (0),
52 mServerChildren (NULL),53 mServerChildren (NULL),
53 mWindowsChanged (false),54 mWindowsChanged (false),
54 mServerWindowsChanged (false),55 mServerWindowsChanged (false),
55 mRoot (root),56 mRoot (root),
56 mDpy (dpy),57 mDpy (dpy),
57 getEventsProc (evProc)58 mFetchXEvent (fetchXEvent)
58{59{
59}60}
6061
@@ -118,11 +119,23 @@
118 mLastServerWindows.push_front (tl);119 mLastServerWindows.push_front (tl);
119}120}
120121
121StackDebugger::eventList122bool
123StackDebugger::getNextEvent (XEvent &ev)
124{
125 if (mEvents.empty ())
126 return false;
127
128 ev = mEvents.front ();
129
130 mEvents.pop_front ();
131
132 return true;
133}
134
135void
122StackDebugger::loadStack (CompWindowList &serverWindows, bool wait)136StackDebugger::loadStack (CompWindowList &serverWindows, bool wait)
123{137{
124 Window rootRet, parentRet;138 Window rootRet, parentRet;
125 eventList events;
126139
127 if (mServerChildren)140 if (mServerChildren)
128 XFree (mServerChildren);141 XFree (mServerChildren);
@@ -132,7 +145,16 @@
132 XQueryTree (mDpy, mRoot, &rootRet, &parentRet,145 XQueryTree (mDpy, mRoot, &rootRet, &parentRet,
133 &mServerChildren, &mServerNChildren);146 &mServerChildren, &mServerNChildren);
134147
135 events = getEventsProc ();148 unsigned int n = XEventsQueued (mDpy, QueuedAfterFlush);
149 mEvents.clear ();
150 mEvents.resize (n);
151 std::list <XEvent>::iterator it = mEvents.begin ();
152
153 while (it != mEvents.end ())
154 {
155 mFetchXEvent->getNextXEvent ((*it));
156 it++;
157 }
136158
137 XSync (mDpy, FALSE);159 XSync (mDpy, FALSE);
138160
@@ -145,7 +167,6 @@
145167
146 if (mServerNChildren != serverWindows.size () && wait)168 if (mServerNChildren != serverWindows.size () && wait)
147 {169 {
148 eventList moreEvents;
149 struct pollfd pfd;170 struct pollfd pfd;
150171
151 pfd.events = POLLIN;172 pfd.events = POLLIN;
@@ -154,10 +175,10 @@
154175
155 poll (&pfd, 1, 300);176 poll (&pfd, 1, 300);
156177
157 moreEvents = getEventsProc ();178 XEvent e;
158179
159 foreach (XEvent e, moreEvents)180 while (mFetchXEvent->getNextXEvent (e))
160 events.push_back (e);181 mEvents.push_back (e);
161182
162 mTimeoutRequired = true;183 mTimeoutRequired = true;
163 }184 }
@@ -166,8 +187,6 @@
166187
167 XUngrabServer (mDpy);188 XUngrabServer (mDpy);
168 XSync (mDpy, FALSE);189 XSync (mDpy, FALSE);
169
170 return events;
171}190}
172191
173void192void

Subscribers

People subscribed via source and target branches