Skip to content

Commit 84bedeb

Browse files
committed
LibWeb: Add fast_is<T> optimization for more paintables
We were doing a lot of dynamic_cast with these types, so let's avoid it.
1 parent 4eca378 commit 84bedeb

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

Libraries/LibWeb/Painting/Paintable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ class WEB_API Paintable
118118
bool fast_is() const = delete;
119119

120120
[[nodiscard]] virtual bool is_navigable_container_viewport_paintable() const { return false; }
121+
[[nodiscard]] virtual bool is_viewport_paintable() const { return false; }
121122
[[nodiscard]] virtual bool is_paintable_box() const { return false; }
122123
[[nodiscard]] virtual bool is_paintable_with_lines() const { return false; }
123124
[[nodiscard]] virtual bool is_svg_paintable() const { return false; }
124125
[[nodiscard]] virtual bool is_svg_svg_paintable() const { return false; }
126+
[[nodiscard]] virtual bool is_svg_path_paintable() const { return false; }
127+
[[nodiscard]] virtual bool is_svg_graphics_paintable() const { return false; }
125128
[[nodiscard]] virtual bool is_text_paintable() const { return false; }
126129

127130
DOM::Document const& document() const;

Libraries/LibWeb/Painting/SVGGraphicsPaintable.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class SVGGraphicsPaintable : public SVGPaintable
7171
SVGGraphicsPaintable(Layout::SVGGraphicsBox const&);
7272

7373
ComputedTransforms m_computed_transforms;
74+
75+
private:
76+
virtual bool is_svg_graphics_paintable() const final { return true; }
7477
};
7578

79+
template<>
80+
inline bool Paintable::fast_is<SVGGraphicsPaintable>() const { return is_svg_graphics_paintable(); }
81+
7682
}

Libraries/LibWeb/Painting/SVGPathPaintable.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class WEB_API SVGPathPaintable final : public SVGGraphicsPaintable {
3737
SVGPathPaintable(Layout::SVGGraphicsBox const&);
3838

3939
Optional<Gfx::Path> m_computed_path = {};
40+
41+
private:
42+
virtual bool is_svg_path_paintable() const final { return true; }
4043
};
4144

45+
template<>
46+
inline bool Paintable::fast_is<SVGPathPaintable>() const { return is_svg_path_paintable(); }
47+
4248
}

Libraries/LibWeb/Painting/ViewportPaintable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class WEB_API ViewportPaintable final : public PaintableWithLines {
4545
ReadonlySpan<GC::Ref<PaintableBox>> paintable_boxes_with_auto_content_visibility() const { return m_paintable_boxes_with_auto_content_visibility; }
4646

4747
private:
48+
virtual bool is_viewport_paintable() const override { return true; }
49+
4850
void build_stacking_context_tree();
4951

5052
explicit ViewportPaintable(Layout::Viewport const&);
@@ -57,4 +59,7 @@ class WEB_API ViewportPaintable final : public PaintableWithLines {
5759
Vector<GC::Ref<PaintableBox>> m_paintable_boxes_with_auto_content_visibility;
5860
};
5961

62+
template<>
63+
inline bool Paintable::fast_is<ViewportPaintable>() const { return is_viewport_paintable(); }
64+
6065
}

0 commit comments

Comments
 (0)