From 7375d8c6f971689983cb5f86562a8601da3f953f Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 10 Sep 2025 11:14:49 +0200 Subject: [PATCH] LibWeb: Simplify ASCII whitespace check in Layout::TextNode No functional changes. --- Libraries/LibWeb/Layout/TextNode.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Libraries/LibWeb/Layout/TextNode.cpp b/Libraries/LibWeb/Layout/TextNode.cpp index 5ec3c793c34..cc91791cd32 100644 --- a/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Libraries/LibWeb/Layout/TextNode.cpp @@ -324,12 +324,12 @@ void TextNode::compute_text_for_rendering() auto data = apply_text_transform(dom_node().data(), computed_values().text_transform(), lang); + // NOTE: A couple fast returns to avoid unnecessarily allocating a StringBuilder. if (!collapse || data.is_empty()) { m_text_for_rendering = move(data); return; } - // NOTE: A couple fast returns to avoid unnecessarily allocating a StringBuilder. if (data.length_in_code_units() == 1) { if (data.is_ascii_whitespace()) m_text_for_rendering = " "_utf16; @@ -338,14 +338,7 @@ void TextNode::compute_text_for_rendering() return; } - bool contains_space = false; - for (auto code_point : data) { - if (is_ascii_space(code_point)) { - contains_space = true; - break; - } - } - if (!contains_space) { + if (!any_of(data, is_ascii_space)) { m_text_for_rendering = move(data); return; } @@ -353,7 +346,7 @@ void TextNode::compute_text_for_rendering() StringBuilder builder(StringBuilder::Mode::UTF16, data.length_in_code_units()); size_t index = 0; - auto skip_over_whitespace = [&]() { + auto skip_over_whitespace = [&] { while (index < data.length_in_code_units() && is_ascii_space(data.code_unit_at(index))) ++index; };