Skip to content

Commit

Permalink
[Cleanup] Remove RenderBox::hasOverridingLogicalWidth
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=273887

Reviewed by Simon Fraser.

This patch eliminates a redundant hash lookup by
1. removing RenderBox:: hasOverridingLogicalWidth and
2. changing the return type of RenderBox::overridingLogicalWidth from LayoutUnit to std::optional<LayoutUnit>

so that the following (highly common) pattern
  if (hasOverridingLogicalWidth())
    ... + overridingLogicalWidth() + ...

can be turned into
  if (auto overridingLogicalWidth = this->overridingLogicalWidth())
    ... + *overridingLogicalWidth + ...

* Source/WebCore/rendering/AutoTableLayout.cpp:
(WebCore::AutoTableLayout::applyPreferredLogicalWidthQuirks const):
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::RenderBox::overridingLogicalWidth const):
(WebCore::RenderBox::computeLogicalWidthInFragment const):
(WebCore::RenderBox::hasOverridingLogicalWidth const): Deleted.
* Source/WebCore/rendering/RenderBox.h:
* Source/WebCore/rendering/RenderBoxInlines.h:
(WebCore::RenderBox::overridingContentLogicalHeight const):
(WebCore::RenderBox::overridingContentLogicalWidth const): Deleted.
* Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::widthForChild):
* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::OverridingSizesScope::OverridingSizesScope):
* Source/WebCore/rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::paint):
* Source/WebCore/rendering/RenderTable.cpp:
(WebCore::RenderTable::updateLogicalWidth):
(WebCore::RenderTable::computePreferredLogicalWidths):

Canonical link: https://commits.webkit.org/278575@main
  • Loading branch information
alanbaradlay committed May 9, 2024
1 parent 9c59162 commit 9ab1368
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/AutoTableLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void AutoTableLayout::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, Layout
void AutoTableLayout::applyPreferredLogicalWidthQuirks(LayoutUnit& minWidth, LayoutUnit& maxWidth) const
{
if (auto tableLogicalWidth = m_table->style().logicalWidth(); tableLogicalWidth.isFixed() && tableLogicalWidth.isPositive()) {
minWidth = std::max(minWidth, m_table->hasOverridingLogicalWidth() ? m_table->overridingLogicalWidth() : LayoutUnit(tableLogicalWidth.value()));
minWidth = std::max(minWidth, m_table->overridingLogicalWidth().value_or(LayoutUnit { tableLogicalWidth.value() }));
maxWidth = minWidth;
}
}
Expand Down
20 changes: 8 additions & 12 deletions Source/WebCore/rendering/RenderBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,11 +1271,6 @@ LayoutUnit RenderBox::maxPreferredLogicalWidth() const
return m_maxPreferredLogicalWidth;
}

bool RenderBox::hasOverridingLogicalWidth() const
{
return gOverridingLogicalWidthMap && gOverridingLogicalWidthMap->contains(*this);
}

void RenderBox::setOverridingLogicalHeight(LayoutUnit height)
{
if (!gOverridingLogicalHeightMap)
Expand Down Expand Up @@ -1308,10 +1303,11 @@ void RenderBox::clearOverridingContentSize()
clearOverridingLogicalWidth();
}

LayoutUnit RenderBox::overridingLogicalWidth() const
std::optional<LayoutUnit> RenderBox::overridingLogicalWidth() const
{
ASSERT(hasOverridingLogicalWidth());
return gOverridingLogicalWidthMap->get(*this);
if (!gOverridingLogicalWidthMap)
return { };
return gOverridingLogicalWidthMap->getOptional(*this);
}

std::optional<LayoutUnit> RenderBox::overridingLogicalHeight() const
Expand Down Expand Up @@ -2679,8 +2675,8 @@ void RenderBox::computeLogicalWidthInFragment(LogicalExtentComputedValues& compu
// width. Use the width from the style context.
// FIXME: Account for block-flow in flexible boxes.
// https://bugs.webkit.org/show_bug.cgi?id=46418
if (hasOverridingLogicalWidth() && parent()->isFlexibleBoxIncludingDeprecated()) {
computedValues.m_extent = overridingLogicalWidth();
if (auto overridingLogicalWidth = (parent()->isFlexibleBoxIncludingDeprecated() ? this->overridingLogicalWidth() : std::nullopt)) {
computedValues.m_extent = *overridingLogicalWidth;
return;
}

Expand Down Expand Up @@ -2718,8 +2714,8 @@ void RenderBox::computeLogicalWidthInFragment(LogicalExtentComputedValues& compu
containerWidthInInlineDirection = perpendicularContainingBlockLogicalHeight();

// Width calculations
if (isGridItem() && hasOverridingLogicalWidth()) {
computedValues.m_extent = overridingLogicalWidth();
if (auto overridingLogicalWidth = (isGridItem() ? this->overridingLogicalWidth() : std::nullopt)) {
computedValues.m_extent = *overridingLogicalWidth;
} else if (treatAsReplaced) {
computedValues.m_extent = logicalWidthLength.value() + borderAndPaddingLogicalWidth();
} else if (shouldComputeLogicalWidthFromAspectRatio() && style().logicalWidth().isAuto()) {
Expand Down
5 changes: 2 additions & 3 deletions Source/WebCore/rendering/RenderBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,15 @@ class RenderBox : public RenderBoxModelObject {
LayoutUnit minPreferredLogicalWidth() const override;
LayoutUnit maxPreferredLogicalWidth() const override;

LayoutUnit overridingLogicalWidth() const;
std::optional<LayoutUnit> overridingLogicalWidth() const;
std::optional<LayoutUnit> overridingLogicalHeight() const;
bool hasOverridingLogicalWidth() const;
void setOverridingLogicalHeight(LayoutUnit);
void setOverridingLogicalWidth(LayoutUnit);
void clearOverridingContentSize();
void clearOverridingLogicalHeight();
void clearOverridingLogicalWidth();

inline LayoutUnit overridingContentLogicalWidth() const;
inline LayoutUnit overridingContentLogicalWidth(LayoutUnit overridingLogicalWidth) const;
inline LayoutUnit overridingContentLogicalHeight(LayoutUnit overridingLogicalHeight) const;

std::optional<LayoutUnit> overridingContainingBlockContentWidth() const override;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/RenderBoxInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline LayoutSize RenderBox::logicalSize() const { return style().isHorizontalWr
inline LayoutUnit RenderBox::logicalTop() const { return style().isHorizontalWritingMode() ? y() : x(); }
inline LayoutUnit RenderBox::logicalWidth() const { return style().isHorizontalWritingMode() ? width() : height(); }
inline LayoutUnit RenderBox::overridingContentLogicalHeight(LayoutUnit overridingLogicalHeight) const { return std::max(0_lu, overridingLogicalHeight - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight() - (style().scrollbarGutter().bothEdges ? scrollbarLogicalHeight() : 0)); }
inline LayoutUnit RenderBox::overridingContentLogicalWidth() const { return std::max(LayoutUnit(), overridingLogicalWidth() - borderAndPaddingLogicalWidth() - scrollbarLogicalWidth() - (style().scrollbarGutter().bothEdges ? scrollbarLogicalWidth() : 0)); }
inline LayoutUnit RenderBox::overridingContentLogicalWidth(LayoutUnit overridingLogicalWidth) const { return std::max(LayoutUnit(), overridingLogicalWidth - borderAndPaddingLogicalWidth() - scrollbarLogicalWidth() - (style().scrollbarGutter().bothEdges ? scrollbarLogicalWidth() : 0)); }
inline LayoutUnit RenderBox::paddingBoxHeight() const { return std::max(0_lu, height() - borderTop() - borderBottom() - horizontalScrollbarHeight()); }
inline LayoutUnit RenderBox::paddingBoxWidth() const { return std::max(0_lu, width() - borderLeft() - borderRight() - verticalScrollbarWidth()); }
inline int RenderBox::scrollbarLogicalHeight() const { return style().isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ static bool childDoesNotAffectWidthOrFlexing(RenderObject* child)

static LayoutUnit widthForChild(RenderBox* child)
{
if (child->hasOverridingLogicalWidth())
return child->overridingLogicalWidth();
if (auto overridingLogicalWidth = child->overridingLogicalWidth())
return *overridingLogicalWidth;
return child->logicalWidth();
}

Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/rendering/RenderFlexibleBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ class OverridingSizesScope {
{
ASSERT(!size || (axis != Axis::Both));
if (axis == Axis::Both || axis == Axis::Inline) {
if (box.hasOverridingLogicalWidth())
m_overridingWidth = box.overridingLogicalWidth();
m_overridingWidth = box.overridingLogicalWidth();
SET_OR_CLEAR_OVERRIDING_SIZE(m_box, Width, size);
}
if (axis == Axis::Both || axis == Axis::Block) {
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/rendering/RenderReplaced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ LayoutUnit RenderReplaced::computeReplacedLogicalHeight(std::optional<LayoutUnit
bool hasIntrinsicWidth = constrainedSize.width() > 0 || shouldApplySizeOrInlineSizeContainment();

// See computeReplacedLogicalHeight() for a similar check for heights.
if (!intrinsicRatio.isEmpty() && (isFlexItem() || isGridItem()) && hasOverridingLogicalWidth() && hasIntrinsicSize(contentRenderer, hasIntrinsicWidth, hasIntrinsicHeight))
return computeReplacedLogicalHeightRespectingMinMaxHeight(overridingContentLogicalWidth() * intrinsicRatio.transposedSize().aspectRatioDouble());
if (auto overridinglogicalWidth = (!intrinsicRatio.isEmpty() && (isFlexItem() || isGridItem()) && hasIntrinsicSize(contentRenderer, hasIntrinsicWidth, hasIntrinsicHeight) ? overridingLogicalWidth() : std::nullopt))
return computeReplacedLogicalHeightRespectingMinMaxHeight(overridingContentLogicalWidth(*overridinglogicalWidth) * intrinsicRatio.transposedSize().aspectRatioDouble());

// If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic height, then that intrinsic height is the used value of 'height'.
if (widthIsAuto && hasIntrinsicHeight)
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/rendering/RenderTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ void RenderTable::updateLogicalWidth()
LayoutUnit containerWidthInInlineDirection = hasPerpendicularContainingBlock ? perpendicularContainingBlockLogicalHeight() : availableLogicalWidth;

Length styleLogicalWidth = style().logicalWidth();
if (hasOverridingLogicalWidth())
setLogicalWidth(overridingLogicalWidth());
if (auto overridingLogicalWidth = this->overridingLogicalWidth())
setLogicalWidth(*overridingLogicalWidth);
else if ((styleLogicalWidth.isSpecified() && styleLogicalWidth.isPositive()) || styleLogicalWidth.isIntrinsic())
setLogicalWidth(convertStyleLogicalWidthToComputedWidth(styleLogicalWidth, containerWidthInInlineDirection));
else {
Expand Down Expand Up @@ -894,9 +894,9 @@ void RenderTable::computePreferredLogicalWidths()
for (unsigned i = 0; i < m_captions.size(); i++)
m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, m_captions[i]->minPreferredLogicalWidth());

if (hasOverridingLogicalWidth()) {
m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, overridingLogicalWidth());
m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, overridingLogicalWidth());
if (auto overridingLogicalWidth = this->overridingLogicalWidth()) {
m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, *overridingLogicalWidth);
m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, *overridingLogicalWidth);
}

auto& styleToUse = style();
Expand Down

0 comments on commit 9ab1368

Please sign in to comment.