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

Proposed by Łukasz Zemczak
Status: Merged
Merged at revision: 3106
Proposed branch: lp:~sil2100/compiz-core/cherry_3236_3237
Merge into: lp:compiz-core
Diff against target: 101 lines (+29/-14)
3 files modified
include/core/option.h (+1/-0)
src/event.cpp (+20/-14)
src/option.cpp (+8/-0)
To merge this branch: bzr merge lp:~sil2100/compiz-core/cherry_3236_3237
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Review via email: mp+111213@code.launchpad.net

Commit message

Cherry-picked from compiz trunk (revs 3236, 3237):
Avoid constructing and destructing lots of strings on every single event, which was wasting lots of CPU (LP: #1005569)
Improve the fix for LP: #1005569:
Calling CompOption::setName should not implicitly construct a new string object every time, when the name is not changing.

This is also an alternative fix to the previous commit, but both together don't hurt either.

Description of the change

A cherry-pick of:
https://code.launchpad.net/~vanvugt/compiz/fix-1005569.1/+merge/107942 and
https://code.launchpad.net/~vanvugt/compiz/fix-1005569.2/+merge/107941

Original descriptions:

Calling CompOption::setName should not implicitly construct a new string
object every time, when the name is not changing. That wastes lots of CPU.
(LP: #1005569)

Avoid constructing and destructing lots of strings on every single event,
which was wasting lots of CPU (LP: #1005569)

To post a comment you must log in.
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

The ugly refactoring in src/event.cpp of mine is not required and only adds risk if you have the setName change already.

However, this fix is approved upstream, it's still smaller than many other changes being backported, and I'm running it right now and don't see any problems (other than bug 1014957).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/option.h'
2--- include/core/option.h 2012-02-16 08:30:33 +0000
3+++ include/core/option.h 2012-06-20 12:47:23 +0000
4@@ -238,6 +238,7 @@
5 ~CompOption ();
6
7 void setName (CompString name, Type type);
8+ void setName (const char *name, Type type);
9
10 void reset ();
11
12
13=== modified file 'src/event.cpp'
14--- src/event.cpp 2012-04-04 03:11:55 +0000
15+++ src/event.cpp 2012-06-20 12:47:23 +0000
16@@ -649,15 +649,19 @@
17 bool
18 PrivateScreen::handleActionEvent (XEvent *event)
19 {
20- static CompOption::Vector o (8);
21+ static CompOption::Vector o;
22 Window xid;
23
24- o[0].setName ("event_window", CompOption::TypeInt);
25- o[1].setName ("window", CompOption::TypeInt);
26- o[2].setName ("modifiers", CompOption::TypeInt);
27- o[3].setName ("x", CompOption::TypeInt);
28- o[4].setName ("y", CompOption::TypeInt);
29- o[5].setName ("root", CompOption::TypeInt);
30+ if (o.empty ())
31+ {
32+ o.resize (8);
33+ o[0].setName ("event_window", CompOption::TypeInt);
34+ o[1].setName ("window", CompOption::TypeInt);
35+ o[2].setName ("modifiers", CompOption::TypeInt);
36+ o[3].setName ("x", CompOption::TypeInt);
37+ o[4].setName ("y", CompOption::TypeInt);
38+ o[5].setName ("root", CompOption::TypeInt);
39+ }
40 o[6].reset ();
41 o[7].reset ();
42
43@@ -937,6 +941,14 @@
44 if (event->type == xkbEvent)
45 {
46 XkbAnyEvent *xkbEvent = (XkbAnyEvent *) event;
47+ static CompOption::Vector o;
48+
49+ if (o.empty ())
50+ {
51+ o.resize (8);
52+ o[0].setName ("event_window", CompOption::TypeInt);
53+ o[1].setName ("window", CompOption::TypeInt);
54+ }
55
56 if (xkbEvent->xkb_type == XkbStateNotify)
57 {
58@@ -944,13 +956,10 @@
59
60 o[0].value ().set ((int) activeWindow);
61 o[1].value ().set ((int) activeWindow);
62+ o[2].setName ("modifiers", CompOption::TypeInt);
63 o[2].value ().set ((int) stateEvent->mods);
64-
65 o[3].setName ("time", CompOption::TypeInt);
66 o[3].value ().set ((int) xkbEvent->time);
67- o[4].reset ();
68- o[5].reset ();
69- o[6].reset ();
70 o[7].value ().set ((int) xkbEvent->time);
71
72 if (stateEvent->event_type == KeyPress)
73@@ -971,9 +980,6 @@
74 o[2].setName ("time", CompOption::TypeInt);
75 o[2].value ().set ((int) xkbEvent->time);
76 o[3].reset ();
77- o[4].reset ();
78- o[5].reset ();
79-
80
81 foreach (CompPlugin *p, CompPlugin::getPlugins ())
82 {
83
84=== modified file 'src/option.cpp'
85--- src/option.cpp 2012-02-20 08:09:35 +0000
86+++ src/option.cpp 2012-06-20 12:47:23 +0000
87@@ -458,6 +458,14 @@
88 priv->type = type;
89 }
90
91+void
92+CompOption::setName (const char *name, CompOption::Type type)
93+{
94+ if (priv->name != name)
95+ priv->name = name;
96+ priv->type = type;
97+}
98+
99 CompString
100 CompOption::name ()
101 {

Subscribers

People subscribed via source and target branches