summaryrefslogtreecommitdiffstats
path: root/src/widget/wpushbutton.cpp
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2016-05-08 13:17:12 -0700
committerRJ Ryan <rryan@mixxx.org>2016-05-08 13:17:12 -0700
commit33552e4f7fda3d06ec282d0fb42df90181872e10 (patch)
tree8d4e812db1a692b6abcef4041e1216650e6a05d7 /src/widget/wpushbutton.cpp
parent6754a0a959b0c50b52d9195f6cda06dfbc21bf9e (diff)
Eliminate SkinContext for WPushButton <State> nodes if the node has no
<SetVariable> sub-nodes. SkinContext creation accounted for 20% of Mixxx bootup so it's important to only create a child context when necessary.
Diffstat (limited to 'src/widget/wpushbutton.cpp')
-rw-r--r--src/widget/wpushbutton.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp
index 49a00335f8..750f3872e8 100644
--- a/src/widget/wpushbutton.cpp
+++ b/src/widget/wpushbutton.cpp
@@ -54,8 +54,9 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) {
setStates(iNumStates);
// Set background pixmap if available
- if (context.hasNode(node, "BackPath")) {
- QDomElement backPathNode = context.selectElement(node, "BackPath");
+
+ QDomElement backPathNode = context.selectElement(node, "BackPath");
+ if (!backPathNode.isNull()) {
PixmapSource backgroundSource = context.getPixmapSource(backPathNode);
if (!backgroundSource.isEmpty()) {
// The implicit default in <1.12.0 was FIXED so we keep it for
@@ -70,34 +71,45 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) {
while (!state.isNull()) {
if (state.isElement() && state.nodeName() == "State") {
// support for variables in State elements
- SkinContext stateContext(context);
- stateContext.updateVariables(state);
- int iState = stateContext.selectInt(state, "Number");
+ // Creating a SkinContext is expensive (nearly 20% of our CPU usage
+ // creating a typical skin from profiling). As an optimization, we
+ // look for "SetVariable" nodes to see if we need to create a
+ // context.
+ QScopedPointer<SkinContext> createdStateContext;
+ if (context.hasVariableUpdates(state)) {
+ createdStateContext.reset(new SkinContext(context));
+ createdStateContext->updateVariables(state);
+ }
+
+ const SkinContext* stateContext = !createdStateContext.isNull() ?
+ createdStateContext.data() : &context;
+
+ int iState = stateContext->selectInt(state, "Number");
if (iState < m_iNoStates) {
- QDomElement unpressedNode = stateContext.selectElement(state, "Unpressed");
- PixmapSource pixmapSource = stateContext.getPixmapSource(unpressedNode);
+ QDomElement unpressedNode = stateContext->selectElement(state, "Unpressed");
+ PixmapSource pixmapSource = stateContext->getPixmapSource(unpressedNode);
// The implicit default in <1.12.0 was FIXED so we keep it for
// backwards compatibility.
Paintable::DrawMode unpressedMode =
- stateContext.selectScaleMode(unpressedNode, Paintable::FIXED);
+ stateContext->selectScaleMode(unpressedNode, Paintable::FIXED);
if (!pixmapSource.isEmpty()) {
setPixmap(iState, false, pixmapSource, unpressedMode);
}
- QDomElement pressedNode = stateContext.selectElement(state, "Pressed");
- pixmapSource = stateContext.getPixmapSource(pressedNode);
+ QDomElement pressedNode = stateContext->selectElement(state, "Pressed");
+ pixmapSource = stateContext->getPixmapSource(pressedNode);
// The implicit default in <1.12.0 was FIXED so we keep it for
// backwards compatibility.
Paintable::DrawMode pressedMode =
- stateContext.selectScaleMode(pressedNode, Paintable::FIXED);
+ stateContext->selectScaleMode(pressedNode, Paintable::FIXED);
if (!pixmapSource.isEmpty()) {
setPixmap(iState, true, pixmapSource, pressedMode);
}
- m_text.replace(iState, stateContext.selectString(state, "Text"));
- QString alignment = stateContext.selectString(state, "Alignment").toLower();
+ m_text.replace(iState, stateContext->selectString(state, "Text"));
+ QString alignment = stateContext->selectString(state, "Alignment").toLower();
if (alignment == "left") {
m_align.replace(iState, Qt::AlignLeft);
} else if (alignment == "right") {