mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
LibWeb: Add a cache for ScrollFrame::cumulative_offset()
Calculating cumulative scroll offset is visible in profiles on very large pages, so let's add a simple caching for it.
This commit is contained in:
parent
112dd4af3b
commit
143c9581a2
Notes:
github-actions[bot]
2024-09-12 05:38:09 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/143c9581a29 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1375
|
@ -22,18 +22,30 @@ public:
|
|||
|
||||
CSSPixelPoint cumulative_offset() const
|
||||
{
|
||||
if (m_parent)
|
||||
return m_parent->cumulative_offset() + m_own_offset;
|
||||
return m_own_offset;
|
||||
if (!m_cached_cumulative_offset.has_value()) {
|
||||
m_cached_cumulative_offset = m_own_offset;
|
||||
if (m_parent) {
|
||||
m_cached_cumulative_offset.value() += m_parent->cumulative_offset();
|
||||
}
|
||||
}
|
||||
return m_cached_cumulative_offset.value();
|
||||
}
|
||||
|
||||
CSSPixelPoint own_offset() const { return m_own_offset; }
|
||||
void set_own_offset(CSSPixelPoint offset) { m_own_offset = offset; }
|
||||
void set_own_offset(CSSPixelPoint offset)
|
||||
{
|
||||
m_cached_cumulative_offset.clear();
|
||||
m_own_offset = offset;
|
||||
}
|
||||
|
||||
private:
|
||||
i32 m_id { -1 };
|
||||
RefPtr<ScrollFrame const> m_parent;
|
||||
CSSPixelPoint m_own_offset;
|
||||
|
||||
// Caching here relies on the fact that offsets of all scroll frames are invalidated when any of them changes,
|
||||
// so we don't need to worry about invalidating the cache when the parent's offset changes.
|
||||
mutable Optional<CSSPixelPoint> m_cached_cumulative_offset;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue