Commit 62fe5b7c authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Eliminate some unnecessary copies of Lengths

Using the Length store directly should work fine most of the time, and
avoids the fairly bloaty Length copy constructor and destructor pair.

Some minor massaging of ValueForPositionOffset required, but otherwise
straightforward.

Change-Id: I1b1d0b14f3897fc4173eab123cc3b241b28c70d3
Reviewed-on: https://chromium-review.googlesource.com/806834Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#521473}
parent 1a70fddf
......@@ -189,27 +189,28 @@ static CSSValue* ValueForFillSourceType(EMaskSourceType type) {
static CSSValue* ValueForPositionOffset(const ComputedStyle& style,
const CSSProperty& property,
const LayoutObject* layout_object) {
Length offset, opposite;
std::pair<const Length*, const Length*> positions;
switch (property.PropertyID()) {
case CSSPropertyLeft:
offset = style.Left();
opposite = style.Right();
positions = std::make_pair(&style.Left(), &style.Right());
break;
case CSSPropertyRight:
offset = style.Right();
opposite = style.Left();
positions = std::make_pair(&style.Right(), &style.Left());
break;
case CSSPropertyTop:
offset = style.Top();
opposite = style.Bottom();
positions = std::make_pair(&style.Top(), &style.Bottom());
break;
case CSSPropertyBottom:
offset = style.Bottom();
opposite = style.Top();
positions = std::make_pair(&style.Bottom(), &style.Top());
break;
default:
NOTREACHED();
return nullptr;
}
DCHECK(positions.first && positions.second);
const Length& offset = *positions.first;
const Length& opposite = *positions.second;
if (offset.IsPercentOrCalc() && layout_object && layout_object->IsBox() &&
layout_object->IsPositioned()) {
......@@ -255,8 +256,9 @@ static CSSValue* ValueForPositionOffset(const ComputedStyle& style,
}
// Length doesn't provide operator -, so multiply by -1.
opposite *= -1.f;
return ZoomAdjustedPixelValueForLength(opposite, style);
Length negated_opposite = opposite;
negated_opposite *= -1.f;
return ZoomAdjustedPixelValueForLength(negated_opposite, style);
}
if (layout_object->IsOutOfFlowPositioned() && layout_object->IsBox()) {
......@@ -699,7 +701,7 @@ ValueForContentPositionAndDistributionWithOverflowAlignment(
}
static CSSValue* ValueForLineHeight(const ComputedStyle& style) {
Length length = style.LineHeight();
const Length& length = style.LineHeight();
if (length.IsNegative())
return CSSIdentifierValue::Create(CSSValueNormal);
......@@ -1464,7 +1466,7 @@ static CSSValue* ValueForAnimationTimingFunction(
return list;
}
static CSSValueList* ValuesForBorderRadiusCorner(LengthSize radius,
static CSSValueList* ValuesForBorderRadiusCorner(const LengthSize& radius,
const ComputedStyle& style) {
CSSValueList* list = CSSValueList::CreateSpaceSeparated();
if (radius.Width().GetType() == kPercent)
......@@ -1480,7 +1482,7 @@ static CSSValueList* ValuesForBorderRadiusCorner(LengthSize radius,
return list;
}
static const CSSValue& ValueForBorderRadiusCorner(LengthSize radius,
static const CSSValue& ValueForBorderRadiusCorner(const LengthSize& radius,
const ComputedStyle& style) {
CSSValueList& list = *ValuesForBorderRadiusCorner(radius, style);
if (list.Item(0) == list.Item(1))
......@@ -2802,14 +2804,14 @@ const CSSValue* ComputedStyleCSSValueMapping::Get(
return CSSIdentifierValue::Create(CSSValueAuto);
return CSSStringValue::Create(style.Locale());
case CSSPropertyMarginTop: {
Length margin_top = style.MarginTop();
const Length& margin_top = style.MarginTop();
if (margin_top.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_top, style);
return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginTop(),
style);
}
case CSSPropertyMarginRight: {
Length margin_right = style.MarginRight();
const Length& margin_right = style.MarginRight();
if (margin_right.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_right, style);
float value;
......@@ -2829,14 +2831,14 @@ const CSSValue* ComputedStyleCSSValueMapping::Get(
return ZoomAdjustedPixelValue(value, style);
}
case CSSPropertyMarginBottom: {
Length margin_bottom = style.MarginBottom();
const Length& margin_bottom = style.MarginBottom();
if (margin_bottom.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_bottom, style);
return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginBottom(),
style);
}
case CSSPropertyMarginLeft: {
Length margin_left = style.MarginLeft();
const Length& margin_left = style.MarginLeft();
if (margin_left.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_left, style);
return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginLeft(),
......@@ -2912,28 +2914,28 @@ const CSSValue* ComputedStyleCSSValueMapping::Get(
case CSSPropertyOverflowY:
return CSSIdentifierValue::Create(style.OverflowY());
case CSSPropertyPaddingTop: {
Length padding_top = style.PaddingTop();
const Length& padding_top = style.PaddingTop();
if (padding_top.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_top, style);
return ZoomAdjustedPixelValue(
ToLayoutBox(layout_object)->ComputedCSSPaddingTop(), style);
}
case CSSPropertyPaddingRight: {
Length padding_right = style.PaddingRight();
const Length& padding_right = style.PaddingRight();
if (padding_right.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_right, style);
return ZoomAdjustedPixelValue(
ToLayoutBox(layout_object)->ComputedCSSPaddingRight(), style);
}
case CSSPropertyPaddingBottom: {
Length padding_bottom = style.PaddingBottom();
const Length& padding_bottom = style.PaddingBottom();
if (padding_bottom.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_bottom, style);
return ZoomAdjustedPixelValue(
ToLayoutBox(layout_object)->ComputedCSSPaddingBottom(), style);
}
case CSSPropertyPaddingLeft: {
Length padding_left = style.PaddingLeft();
const Length& padding_left = style.PaddingLeft();
if (padding_left.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_left, style);
return ZoomAdjustedPixelValue(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment