From d1076c1e6ea772e2bf28e6216803850db2a8503a Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 10 Sep 2025 15:52:34 +0200 Subject: [PATCH] LibWeb: Remove text storage from TextPaintable Instead of copying the layout node's text, retrieve the text from the layout node directly. --- Libraries/LibWeb/Layout/TextNode.cpp | 2 +- Libraries/LibWeb/Page/EventHandler.cpp | 2 +- Libraries/LibWeb/Painting/PaintableFragment.cpp | 2 +- Libraries/LibWeb/Painting/TextPaintable.cpp | 7 +++---- Libraries/LibWeb/Painting/TextPaintable.h | 8 ++------ 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Libraries/LibWeb/Layout/TextNode.cpp b/Libraries/LibWeb/Layout/TextNode.cpp index 3b9cf1714f7..f896e420602 100644 --- a/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Libraries/LibWeb/Layout/TextNode.cpp @@ -555,7 +555,7 @@ Optional TextNode::ChunkIterator::try_commit_chunk(size_t start GC::Ptr TextNode::create_paintable() const { - return Painting::TextPaintable::create(*this, text_for_rendering()); + return Painting::TextPaintable::create(*this); } } diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 547d5136cf0..92222cf73f6 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -986,7 +986,7 @@ EventResult EventHandler::handle_doubleclick(CSSPixelPoint viewport_position, CS next_boundary = hit_dom_node.length_in_utf16_code_units(); } else { auto& segmenter = word_segmenter(); - segmenter.set_segmented_text(hit_paintable.text_for_rendering()); + segmenter.set_segmented_text(hit_paintable.layout_node().text_for_rendering()); previous_boundary = segmenter.previous_boundary(result->index_in_node, Unicode::Segmenter::Inclusive::Yes).value_or(0); next_boundary = segmenter.next_boundary(result->index_in_node).value_or(hit_dom_node.length()); diff --git a/Libraries/LibWeb/Painting/PaintableFragment.cpp b/Libraries/LibWeb/Painting/PaintableFragment.cpp index e5e06b30ce1..643d19f3ca5 100644 --- a/Libraries/LibWeb/Painting/PaintableFragment.cpp +++ b/Libraries/LibWeb/Painting/PaintableFragment.cpp @@ -208,7 +208,7 @@ Utf16View PaintableFragment::text() const { if (!is(paintable())) return {}; - return static_cast(paintable()).text_for_rendering().substring_view(m_start_offset, m_length_in_code_units); + return as(paintable()).layout_node().text_for_rendering().substring_view(m_start_offset, m_length_in_code_units); } } diff --git a/Libraries/LibWeb/Painting/TextPaintable.cpp b/Libraries/LibWeb/Painting/TextPaintable.cpp index ccb06b1dad4..692d2da43bc 100644 --- a/Libraries/LibWeb/Painting/TextPaintable.cpp +++ b/Libraries/LibWeb/Painting/TextPaintable.cpp @@ -14,14 +14,13 @@ namespace Web::Painting { GC_DEFINE_ALLOCATOR(TextPaintable); -GC::Ref TextPaintable::create(Layout::TextNode const& layout_node, Utf16String text_for_rendering) +GC::Ref TextPaintable::create(Layout::TextNode const& layout_node) { - return layout_node.heap().allocate(layout_node, move(text_for_rendering)); + return layout_node.heap().allocate(layout_node); } -TextPaintable::TextPaintable(Layout::TextNode const& layout_node, Utf16String text_for_rendering) +TextPaintable::TextPaintable(Layout::TextNode const& layout_node) : Paintable(layout_node) - , m_text_for_rendering(move(text_for_rendering)) { } diff --git a/Libraries/LibWeb/Painting/TextPaintable.h b/Libraries/LibWeb/Painting/TextPaintable.h index 91659a1df47..6f4cfbeb136 100644 --- a/Libraries/LibWeb/Painting/TextPaintable.h +++ b/Libraries/LibWeb/Painting/TextPaintable.h @@ -16,7 +16,7 @@ class TextPaintable final : public Paintable { GC_DECLARE_ALLOCATOR(TextPaintable); public: - static GC::Ref create(Layout::TextNode const&, Utf16String text_for_rendering); + static GC::Ref create(Layout::TextNode const&); Layout::TextNode const& layout_node() const { return static_cast(Paintable::layout_node()); } @@ -25,14 +25,10 @@ public: virtual DispatchEventOfSameName handle_mouseup(Badge, CSSPixelPoint, unsigned button, unsigned modifiers) override; virtual DispatchEventOfSameName handle_mousemove(Badge, CSSPixelPoint, unsigned button, unsigned modifiers) override; - Utf16String const& text_for_rendering() const { return m_text_for_rendering; } - private: virtual bool is_text_paintable() const override { return true; } - TextPaintable(Layout::TextNode const&, Utf16String text_for_rendering); - - Utf16String m_text_for_rendering; + TextPaintable(Layout::TextNode const&); }; }