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) { ...@@ -189,27 +189,28 @@ static CSSValue* ValueForFillSourceType(EMaskSourceType type) {
static CSSValue* ValueForPositionOffset(const ComputedStyle& style, static CSSValue* ValueForPositionOffset(const ComputedStyle& style,
const CSSProperty& property, const CSSProperty& property,
const LayoutObject* layout_object) { const LayoutObject* layout_object) {
Length offset, opposite; std::pair<const Length*, const Length*> positions;
switch (property.PropertyID()) { switch (property.PropertyID()) {
case CSSPropertyLeft: case CSSPropertyLeft:
offset = style.Left(); positions = std::make_pair(&style.Left(), &style.Right());
opposite = style.Right();
break; break;
case CSSPropertyRight: case CSSPropertyRight:
offset = style.Right(); positions = std::make_pair(&style.Right(), &style.Left());
opposite = style.Left();
break; break;
case CSSPropertyTop: case CSSPropertyTop:
offset = style.Top(); positions = std::make_pair(&style.Top(), &style.Bottom());
opposite = style.Bottom();
break; break;
case CSSPropertyBottom: case CSSPropertyBottom:
offset = style.Bottom(); positions = std::make_pair(&style.Bottom(), &style.Top());
opposite = style.Top();
break; break;
default: default:
NOTREACHED();
return nullptr; 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() && if (offset.IsPercentOrCalc() && layout_object && layout_object->IsBox() &&
layout_object->IsPositioned()) { layout_object->IsPositioned()) {
...@@ -255,8 +256,9 @@ static CSSValue* ValueForPositionOffset(const ComputedStyle& style, ...@@ -255,8 +256,9 @@ static CSSValue* ValueForPositionOffset(const ComputedStyle& style,
} }
// Length doesn't provide operator -, so multiply by -1. // Length doesn't provide operator -, so multiply by -1.
opposite *= -1.f; Length negated_opposite = opposite;
return ZoomAdjustedPixelValueForLength(opposite, style); negated_opposite *= -1.f;
return ZoomAdjustedPixelValueForLength(negated_opposite, style);
} }
if (layout_object->IsOutOfFlowPositioned() && layout_object->IsBox()) { if (layout_object->IsOutOfFlowPositioned() && layout_object->IsBox()) {
...@@ -699,7 +701,7 @@ ValueForContentPositionAndDistributionWithOverflowAlignment( ...@@ -699,7 +701,7 @@ ValueForContentPositionAndDistributionWithOverflowAlignment(
} }
static CSSValue* ValueForLineHeight(const ComputedStyle& style) { static CSSValue* ValueForLineHeight(const ComputedStyle& style) {
Length length = style.LineHeight(); const Length& length = style.LineHeight();
if (length.IsNegative()) if (length.IsNegative())
return CSSIdentifierValue::Create(CSSValueNormal); return CSSIdentifierValue::Create(CSSValueNormal);
...@@ -1464,7 +1466,7 @@ static CSSValue* ValueForAnimationTimingFunction( ...@@ -1464,7 +1466,7 @@ static CSSValue* ValueForAnimationTimingFunction(
return list; return list;
} }
static CSSValueList* ValuesForBorderRadiusCorner(LengthSize radius, static CSSValueList* ValuesForBorderRadiusCorner(const LengthSize& radius,
const ComputedStyle& style) { const ComputedStyle& style) {
CSSValueList* list = CSSValueList::CreateSpaceSeparated(); CSSValueList* list = CSSValueList::CreateSpaceSeparated();
if (radius.Width().GetType() == kPercent) if (radius.Width().GetType() == kPercent)
...@@ -1480,7 +1482,7 @@ static CSSValueList* ValuesForBorderRadiusCorner(LengthSize radius, ...@@ -1480,7 +1482,7 @@ static CSSValueList* ValuesForBorderRadiusCorner(LengthSize radius,
return list; return list;
} }
static const CSSValue& ValueForBorderRadiusCorner(LengthSize radius, static const CSSValue& ValueForBorderRadiusCorner(const LengthSize& radius,
const ComputedStyle& style) { const ComputedStyle& style) {
CSSValueList& list = *ValuesForBorderRadiusCorner(radius, style); CSSValueList& list = *ValuesForBorderRadiusCorner(radius, style);
if (list.Item(0) == list.Item(1)) if (list.Item(0) == list.Item(1))
...@@ -2802,14 +2804,14 @@ const CSSValue* ComputedStyleCSSValueMapping::Get( ...@@ -2802,14 +2804,14 @@ const CSSValue* ComputedStyleCSSValueMapping::Get(
return CSSIdentifierValue::Create(CSSValueAuto); return CSSIdentifierValue::Create(CSSValueAuto);
return CSSStringValue::Create(style.Locale()); return CSSStringValue::Create(style.Locale());
case CSSPropertyMarginTop: { case CSSPropertyMarginTop: {
Length margin_top = style.MarginTop(); const Length& margin_top = style.MarginTop();
if (margin_top.IsFixed() || !layout_object || !layout_object->IsBox()) if (margin_top.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_top, style); return ZoomAdjustedPixelValueForLength(margin_top, style);
return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginTop(), return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginTop(),
style); style);
} }
case CSSPropertyMarginRight: { case CSSPropertyMarginRight: {
Length margin_right = style.MarginRight(); const Length& margin_right = style.MarginRight();
if (margin_right.IsFixed() || !layout_object || !layout_object->IsBox()) if (margin_right.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_right, style); return ZoomAdjustedPixelValueForLength(margin_right, style);
float value; float value;
...@@ -2829,14 +2831,14 @@ const CSSValue* ComputedStyleCSSValueMapping::Get( ...@@ -2829,14 +2831,14 @@ const CSSValue* ComputedStyleCSSValueMapping::Get(
return ZoomAdjustedPixelValue(value, style); return ZoomAdjustedPixelValue(value, style);
} }
case CSSPropertyMarginBottom: { case CSSPropertyMarginBottom: {
Length margin_bottom = style.MarginBottom(); const Length& margin_bottom = style.MarginBottom();
if (margin_bottom.IsFixed() || !layout_object || !layout_object->IsBox()) if (margin_bottom.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_bottom, style); return ZoomAdjustedPixelValueForLength(margin_bottom, style);
return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginBottom(), return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginBottom(),
style); style);
} }
case CSSPropertyMarginLeft: { case CSSPropertyMarginLeft: {
Length margin_left = style.MarginLeft(); const Length& margin_left = style.MarginLeft();
if (margin_left.IsFixed() || !layout_object || !layout_object->IsBox()) if (margin_left.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(margin_left, style); return ZoomAdjustedPixelValueForLength(margin_left, style);
return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginLeft(), return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginLeft(),
...@@ -2912,28 +2914,28 @@ const CSSValue* ComputedStyleCSSValueMapping::Get( ...@@ -2912,28 +2914,28 @@ const CSSValue* ComputedStyleCSSValueMapping::Get(
case CSSPropertyOverflowY: case CSSPropertyOverflowY:
return CSSIdentifierValue::Create(style.OverflowY()); return CSSIdentifierValue::Create(style.OverflowY());
case CSSPropertyPaddingTop: { case CSSPropertyPaddingTop: {
Length padding_top = style.PaddingTop(); const Length& padding_top = style.PaddingTop();
if (padding_top.IsFixed() || !layout_object || !layout_object->IsBox()) if (padding_top.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_top, style); return ZoomAdjustedPixelValueForLength(padding_top, style);
return ZoomAdjustedPixelValue( return ZoomAdjustedPixelValue(
ToLayoutBox(layout_object)->ComputedCSSPaddingTop(), style); ToLayoutBox(layout_object)->ComputedCSSPaddingTop(), style);
} }
case CSSPropertyPaddingRight: { case CSSPropertyPaddingRight: {
Length padding_right = style.PaddingRight(); const Length& padding_right = style.PaddingRight();
if (padding_right.IsFixed() || !layout_object || !layout_object->IsBox()) if (padding_right.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_right, style); return ZoomAdjustedPixelValueForLength(padding_right, style);
return ZoomAdjustedPixelValue( return ZoomAdjustedPixelValue(
ToLayoutBox(layout_object)->ComputedCSSPaddingRight(), style); ToLayoutBox(layout_object)->ComputedCSSPaddingRight(), style);
} }
case CSSPropertyPaddingBottom: { case CSSPropertyPaddingBottom: {
Length padding_bottom = style.PaddingBottom(); const Length& padding_bottom = style.PaddingBottom();
if (padding_bottom.IsFixed() || !layout_object || !layout_object->IsBox()) if (padding_bottom.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_bottom, style); return ZoomAdjustedPixelValueForLength(padding_bottom, style);
return ZoomAdjustedPixelValue( return ZoomAdjustedPixelValue(
ToLayoutBox(layout_object)->ComputedCSSPaddingBottom(), style); ToLayoutBox(layout_object)->ComputedCSSPaddingBottom(), style);
} }
case CSSPropertyPaddingLeft: { case CSSPropertyPaddingLeft: {
Length padding_left = style.PaddingLeft(); const Length& padding_left = style.PaddingLeft();
if (padding_left.IsFixed() || !layout_object || !layout_object->IsBox()) if (padding_left.IsFixed() || !layout_object || !layout_object->IsBox())
return ZoomAdjustedPixelValueForLength(padding_left, style); return ZoomAdjustedPixelValueForLength(padding_left, style);
return ZoomAdjustedPixelValue( 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