1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 14:15:08 +00:00

LibWeb: Avoid some redundant resolution of padding values during layout

Padding is not affected by the width constraining algorithm, so we can
just resolve it up front.
This commit is contained in:
Andreas Kling 2020-06-25 12:14:26 +02:00
parent afcfea2001
commit 58f76ed11f

View file

@ -278,20 +278,17 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
auto& containing_block = *this->containing_block(); auto& containing_block = *this->containing_block();
auto zero_value = Length::make_px(0); auto zero_value = Length::make_px(0);
Length margin_left = Length::make_auto(); auto margin_left = Length::make_auto();
Length margin_right = Length::make_auto(); auto margin_right = Length::make_auto();
const auto border_left = style().border_left().width; const auto border_left = style().border_left().width;
const auto border_right = style().border_right().width; const auto border_right = style().border_right().width;
Length padding_left = Length::make_auto(); const auto padding_left = style().padding().left.resolved(zero_value, *this, containing_block.width());
Length padding_right = Length::make_auto(); const auto padding_right = style().padding().right.resolved(zero_value, *this, containing_block.width());
auto try_compute_width = [&](const auto& a_width) { auto try_compute_width = [&](const auto& a_width) {
margin_left = style().margin().left.resolved(zero_value, *this, containing_block.width()); margin_left = style().margin().left.resolved(zero_value, *this, containing_block.width());
margin_right = style().margin().right.resolved(zero_value, *this, containing_block.width()); margin_right = style().margin().right.resolved(zero_value, *this, containing_block.width());
padding_left = style().padding().left.resolved(zero_value, *this, containing_block.width());
padding_right = style().padding().right.resolved(zero_value, *this, containing_block.width());
auto left = style().offset().left.resolved_or_auto(*this, containing_block.width()); auto left = style().offset().left.resolved_or_auto(*this, containing_block.width());
auto right = style().offset().right.resolved_or_auto(*this, containing_block.width()); auto right = style().offset().right.resolved_or_auto(*this, containing_block.width());
auto width = a_width; auto width = a_width;
@ -420,21 +417,18 @@ void LayoutBlock::compute_width()
if (is_absolutely_positioned()) if (is_absolutely_positioned())
return compute_width_for_absolutely_positioned_block(); return compute_width_for_absolutely_positioned_block();
auto& containing_block = *this->containing_block();
auto zero_value = Length::make_px(0); auto zero_value = Length::make_px(0);
Length margin_left = Length::make_auto(); auto margin_left = Length::make_auto();
Length margin_right = Length::make_auto(); auto margin_right = Length::make_auto();
Length padding_left = Length::make_auto(); const auto padding_left = style().padding().left.resolved_or_zero(*this, containing_block.width());
Length padding_right = Length::make_auto(); const auto padding_right = style().padding().right.resolved_or_zero(*this, containing_block.width());
auto& containing_block = *this->containing_block();
auto try_compute_width = [&](const auto& a_width) { auto try_compute_width = [&](const auto& a_width) {
Length width = a_width; Length width = a_width;
margin_left = style().margin().left.resolved_or_zero(*this, containing_block.width()); margin_left = style().margin().left.resolved_or_zero(*this, containing_block.width());
margin_right = style().margin().right.resolved_or_zero(*this, containing_block.width()); margin_right = style().margin().right.resolved_or_zero(*this, containing_block.width());
padding_left = style().padding().left.resolved_or_zero(*this, containing_block.width());
padding_right = style().padding().right.resolved_or_zero(*this, containing_block.width());
float total_px = style().border_left().width + style().border_right().width; float total_px = style().border_left().width + style().border_right().width;
for (auto& value : { margin_left, padding_left, width, padding_right, margin_right }) { for (auto& value : { margin_left, padding_left, width, padding_right, margin_right }) {