Commit 53031824 authored by Oriol Brufau's avatar Oriol Brufau Committed by Commit Bot

[css-grid] Return cached track sizes by reference

Currently GridTrackSizingAlgorithmStrategy::GetCachedGridTrackSize and
GridTrack::CachedTrackSize don't return the GridTrackSize by reference.

This means that some code like

  const GridLength& length = track.CachedTrackSize().MaxTrackBreadth();
  DCHECK(length.IsFlex());

has a stack-use-after-scope issue, since GridTrackSize::MaxTrackBreadth
returns a GridLength by reference, which will point to the temporary
object returned by CachedTrackSize.

To avoid this problem, this patch makes GetCachedGridTrackSize and
CachedTrackSize return a const reference instead of a temporary copy.

Change-Id: I3e43bf88a475b30747a101195705a22d93cc52a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919140Reviewed-by: default avatarSergio Villar <svillar@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#715665}
parent 6e3e930c
...@@ -66,7 +66,7 @@ class GridTrack { ...@@ -66,7 +66,7 @@ class GridTrack {
} }
void SetGrowthLimitCap(base::Optional<LayoutUnit>); void SetGrowthLimitCap(base::Optional<LayoutUnit>);
const GridTrackSize CachedTrackSize() const { const GridTrackSize& CachedTrackSize() const {
DCHECK(cached_track_size_.has_value()); DCHECK(cached_track_size_.has_value());
return cached_track_size_.value(); return cached_track_size_.value();
} }
...@@ -325,8 +325,9 @@ class GridTrackSizingAlgorithmStrategy { ...@@ -325,8 +325,9 @@ class GridTrackSizingAlgorithmStrategy {
return algorithm_.AvailableSpace(); return algorithm_.AvailableSpace();
} }
GridTrackSize GetCachedGridTrackSize(GridTrackSizingDirection direction, const GridTrackSize& GetCachedGridTrackSize(
size_t translated_index) const { GridTrackSizingDirection direction,
size_t translated_index) const {
return algorithm_.Tracks(direction)[translated_index].CachedTrackSize(); return algorithm_.Tracks(direction)[translated_index].CachedTrackSize();
} }
......
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