[FrameSvg] Optimize updateSizes

frame->fooHeight is the same as frame->fooFixedHeight if the border is enabled, we only meddle
with margins, not heights. Thus we can just do the lookup once and re-use the value.

Also store the hintFooMargin instead of doing the same exact lookup once for fixed
and once for non-fixed margins.

Differential Revision: https://phabricator.kde.org/D8135
This commit is contained in:
Kai Uwe Broulik 2017-10-16 11:38:09 +02:00
parent ecd00a565a
commit dea8a1ed5f

View File

@ -844,18 +844,20 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
//This has the same size regardless the border is enabled or not //This has the same size regardless the border is enabled or not
frame->fixedTopHeight = q->elementSize(frame->prefix % QLatin1String("top")).height(); frame->fixedTopHeight = q->elementSize(frame->prefix % QLatin1String("top")).height();
int hintTopMargin = -1;
if (q->hasElement(frame->prefix % QLatin1String("hint-top-margin"))) { if (q->hasElement(frame->prefix % QLatin1String("hint-top-margin"))) {
frame->fixedTopMargin = q->elementSize(frame->prefix % QLatin1String("hint-top-margin")).height(); hintTopMargin = q->elementSize(frame->prefix % QLatin1String("hint-top-margin")).height();
frame->fixedTopMargin = hintTopMargin;
} else { } else {
frame->fixedTopMargin = frame->fixedTopHeight; frame->fixedTopMargin = frame->fixedTopHeight;
} }
//The same, but its size depends from the margin being enabled //The same, but its size depends from the margin being enabled
if (frame->enabledBorders & FrameSvg::TopBorder) { if (frame->enabledBorders & FrameSvg::TopBorder) {
frame->topHeight = q->elementSize(frame->prefix % QLatin1String("top")).height(); frame->topHeight = frame->fixedTopHeight;
if (q->hasElement(frame->prefix % QLatin1String("hint-top-margin"))) { if (hintTopMargin > -1) {
frame->topMargin = q->elementSize(frame->prefix % QLatin1String("hint-top-margin")).height(); frame->topMargin = hintTopMargin;
} else { } else {
frame->topMargin = frame->topHeight; frame->topMargin = frame->topHeight;
} }
@ -865,17 +867,19 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
frame->fixedLeftWidth = q->elementSize(frame->prefix % QLatin1String("left")).width(); frame->fixedLeftWidth = q->elementSize(frame->prefix % QLatin1String("left")).width();
int hintLeftMargin = -1;
if (q->hasElement(frame->prefix % QLatin1String("hint-left-margin"))) { if (q->hasElement(frame->prefix % QLatin1String("hint-left-margin"))) {
frame->fixedLeftMargin = q->elementSize(frame->prefix % QLatin1String("hint-left-margin")).width(); hintLeftMargin = q->elementSize(frame->prefix % QLatin1String("hint-left-margin")).width();
frame->fixedLeftMargin = hintLeftMargin;
} else { } else {
frame->fixedLeftMargin = frame->fixedLeftWidth; frame->fixedLeftMargin = frame->fixedLeftWidth;
} }
if (frame->enabledBorders & FrameSvg::LeftBorder) { if (frame->enabledBorders & FrameSvg::LeftBorder) {
frame->leftWidth = q->elementSize(frame->prefix % QLatin1String("left")).width(); frame->leftWidth = frame->fixedLeftWidth;
if (q->hasElement(frame->prefix % QLatin1String("hint-left-margin"))) { if (hintLeftMargin > -1) {
frame->leftMargin = q->elementSize(frame->prefix % QLatin1String("hint-left-margin")).width(); frame->leftMargin = hintLeftMargin;
} else { } else {
frame->leftMargin = frame->leftWidth; frame->leftMargin = frame->leftWidth;
} }
@ -885,17 +889,19 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
frame->fixedRightWidth = q->elementSize(frame->prefix % QLatin1String("right")).width(); frame->fixedRightWidth = q->elementSize(frame->prefix % QLatin1String("right")).width();
int hintRightMargin = -1;
if (q->hasElement(frame->prefix % QLatin1String("hint-right-margin"))) { if (q->hasElement(frame->prefix % QLatin1String("hint-right-margin"))) {
frame->fixedRightMargin = q->elementSize(frame->prefix % QLatin1String("hint-right-margin")).width(); hintRightMargin = q->elementSize(frame->prefix % QLatin1String("hint-right-margin")).width();
frame->fixedRightMargin = hintRightMargin;
} else { } else {
frame->fixedRightMargin = frame->fixedRightWidth; frame->fixedRightMargin = frame->fixedRightWidth;
} }
if (frame->enabledBorders & FrameSvg::RightBorder) { if (frame->enabledBorders & FrameSvg::RightBorder) {
frame->rightWidth = q->elementSize(frame->prefix % QLatin1String("right")).width(); frame->rightWidth = frame->fixedRightWidth;
if (q->hasElement(frame->prefix % QLatin1String("hint-right-margin"))) { if (hintRightMargin > -1) {
frame->rightMargin = q->elementSize(frame->prefix % QLatin1String("hint-right-margin")).width(); frame->rightMargin = hintRightMargin;
} else { } else {
frame->rightMargin = frame->rightWidth; frame->rightMargin = frame->rightWidth;
} }
@ -905,17 +911,19 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
frame->fixedBottomHeight = q->elementSize(frame->prefix % QLatin1String("bottom")).height(); frame->fixedBottomHeight = q->elementSize(frame->prefix % QLatin1String("bottom")).height();
int hintBottomMargin = -1;
if (q->hasElement(frame->prefix % QLatin1String("hint-bottom-margin"))) { if (q->hasElement(frame->prefix % QLatin1String("hint-bottom-margin"))) {
frame->fixedBottomMargin = q->elementSize(frame->prefix % QLatin1String("hint-bottom-margin")).height(); hintBottomMargin = q->elementSize(frame->prefix % QLatin1String("hint-bottom-margin")).height();
frame->fixedBottomMargin = hintBottomMargin;
} else { } else {
frame->fixedBottomMargin = frame->fixedBottomHeight; frame->fixedBottomMargin = frame->fixedBottomHeight;
} }
if (frame->enabledBorders & FrameSvg::BottomBorder) { if (frame->enabledBorders & FrameSvg::BottomBorder) {
frame->bottomHeight = q->elementSize(frame->prefix % QLatin1String("bottom")).height(); frame->bottomHeight = frame->fixedBottomHeight;
if (q->hasElement(frame->prefix % QLatin1String("hint-bottom-margin"))) { if (hintBottomMargin > -1) {
frame->bottomMargin = q->elementSize(frame->prefix % QLatin1String("hint-bottom-margin")).height(); frame->bottomMargin = hintBottomMargin;
} else { } else {
frame->bottomMargin = frame->bottomHeight; frame->bottomMargin = frame->bottomHeight;
} }