From 267b9d12b6f8cc4218a761c2a7e92ca350b7f6a6 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Tue, 9 Nov 2010 21:11:29 +0800 Subject: [PATCH] Be a little bit more clever when handing option construction in handleActionEvent. Previously we would have a static CompAction::Vector which we would resize to lower sizes (so that triggerFooBindings doesn't die) but this causes us to be reconstruction CompOptions all the time which is expensive. Instead just reset the option to make it "dead" (eg keep it in memory for longer) but don't create and recreate them all the time Also copy the active state of a CompAction on copy-construct --- include/core/option.h | 8 +++++--- src/action.cpp | 3 ++- src/event.cpp | 25 ++++++++++--------------- src/option.cpp | 15 +++++++++++---- src/privateoption.h | 2 ++ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/include/core/option.h b/include/core/option.h index 09cf033..934a133 100644 --- a/include/core/option.h +++ b/include/core/option.h @@ -64,7 +64,7 @@ class CompOption { /* internal use only */ TypeUnset } Type; - + /** * A value of an Option */ @@ -126,7 +126,7 @@ class CompOption { private: PrivateValue *priv; }; - + /** * TODO */ @@ -154,7 +154,7 @@ class CompOption { }; typedef std::vector Vector; - + /** * TODO */ @@ -176,6 +176,8 @@ class CompOption { void setName (CompString name, Type type); + void reset (); + CompString name (); Type type (); diff --git a/src/action.cpp b/src/action.cpp index 2c97244..14153c4 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -648,7 +648,8 @@ PrivateAction::PrivateAction (const PrivateAction& a) : key (a.key), button (a.button), bell (a.bell), - edgeMask (a.edgeMask) + edgeMask (a.edgeMask), + active (a.active) { memcpy (&priv, &a.priv, sizeof (CompPrivate)); } diff --git a/src/event.cpp b/src/event.cpp index 15768d1..34e3a34 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -618,7 +618,6 @@ PrivateScreen::handleActionEvent (XEvent *event) { static CompOption::Vector o (8); Window xid; - o.resize (8); o[0].setName ("event_window", CompOption::TypeInt); o[1].setName ("window", CompOption::TypeInt); @@ -626,6 +625,8 @@ PrivateScreen::handleActionEvent (XEvent *event) o[3].setName ("x", CompOption::TypeInt); o[4].setName ("y", CompOption::TypeInt); o[5].setName ("root", CompOption::TypeInt); + o[6].reset (); + o[7].reset (); switch (event->type) { case ButtonPress: @@ -764,8 +765,6 @@ PrivateScreen::handleActionEvent (XEvent *event) o[6].setName ("time", CompOption::TypeInt); o[6].value ().set ((int) event->xcrossing.time); - - o.resize (7); foreach (CompPlugin *p, CompPlugin::getPlugins ()) { @@ -801,8 +800,6 @@ PrivateScreen::handleActionEvent (XEvent *event) o[6].setName ("time", CompOption::TypeInt); o[6].value ().set ((int) event->xcrossing.time); - - o.resize (7); if (triggerEdgeEnter (edge, state, o)) return true; @@ -849,8 +846,6 @@ PrivateScreen::handleActionEvent (XEvent *event) o[3].value ().set ((int) 0); /* fixme */ o[4].value ().set ((int) 0); /* fixme */ o[5].value ().set ((int) root); - - o.resize (6); foreach (CompPlugin *p, CompPlugin::getPlugins ()) { @@ -895,8 +890,6 @@ PrivateScreen::handleActionEvent (XEvent *event) o[3].value ().set ((int) event->xclient.data.l[2] >> 16); o[4].value ().set ((int) event->xclient.data.l[2] & 0xffff); o[5].value ().set ((int) root); - - o.resize (6); if (triggerEdgeEnter (edge, state, o)) return true; @@ -918,10 +911,10 @@ PrivateScreen::handleActionEvent (XEvent *event) o[1].value ().set ((int) activeWindow); o[2].value ().set ((int) stateEvent->mods); - o[3] = CompOption ("time", CompOption::TypeInt); + o[3].setName ("time", CompOption::TypeInt); o[3].value ().set ((int) xkbEvent->time); - - o.resize (4); + o[4].reset (); + o[5].reset (); foreach (CompPlugin *p, CompPlugin::getPlugins ()) { @@ -935,10 +928,12 @@ PrivateScreen::handleActionEvent (XEvent *event) o[0].value ().set ((int) activeWindow); o[1].value ().set ((int) activeWindow); - o[2] = CompOption ("time", CompOption::TypeInt); + o[2].setName ("time", CompOption::TypeInt); o[2].value ().set ((int) xkbEvent->time); + o[3].reset (); + o[4].reset (); + o[5].reset (); - o.resize (3); foreach (CompPlugin *p, CompPlugin::getPlugins ()) { @@ -1734,7 +1729,7 @@ CompScreen::handleEvent (XEvent *event) { w = findWindow (((XShapeEvent *) event)->window); if (w) - { + { if (w->mapNum ()) w->priv->updateRegion (); } diff --git a/src/option.cpp b/src/option.cpp index 2de2f9e..78fdc0f 100644 --- a/src/option.cpp +++ b/src/option.cpp @@ -586,7 +586,7 @@ CompOption::Restriction::operator= (const CompOption::Restriction &rest) { if (this == &rest) return *this; - + delete priv; priv = new PrivateRestriction (*rest.priv); return *this; @@ -692,6 +692,13 @@ CompOption::~CompOption () } void +CompOption::reset () +{ + priv->name = ""; + priv->type = TypeUnset; +} + +void CompOption::setName (CompString name, CompOption::Type type) { priv->name = name; @@ -776,13 +783,13 @@ CompOption::set (CompOption::Value &val) return false; case CompOption::TypeKey: - if (val.action ().type () == value().action ().type () && + if (val.action ().type () == value().action ().type () && !(val.action ().type () & CompAction::BindingTypeKey)) return false; break; case CompOption::TypeButton: - if (val.action ().type () == value().action ().type () && + if (val.action ().type () == value().action ().type () && !(val.action ().type () & (CompAction::BindingTypeButton | CompAction::BindingTypeEdgeButton))) return false; @@ -808,7 +815,7 @@ CompOption::operator= (const CompOption &option) { if (this == &option) return *this; - + delete priv; priv = new PrivateOption (*option.priv); return *this; diff --git a/src/privateoption.h b/src/privateoption.h index 1749554..0b00fb0 100644 --- a/src/privateoption.h +++ b/src/privateoption.h @@ -78,6 +78,8 @@ class PrivateValue { CompMatch match; CompOption::Type listType; CompOption::Value::Vector list; + + bool active; }; class PrivateOption -- cgit v1.1