From 7e406ac668dc1acd1767bc7d7a67df4ccb217e87 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 1 Dec 2024 22:18:09 +0100 Subject: [PATCH] LibWeb: Simplify editing algorithm for "ends in space" condition Checking if a string ends in a space does not require converting UTF-8 to UTF-16 and reading out its code points. --- Libraries/LibWeb/Editing/Internal/Algorithms.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index ec3431ef7e5..63abb7f0051 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -261,14 +261,8 @@ void canonicalize_whitespace(GC::Ref node, u32 offset, bool fix_colla auto* layout_node = end_node->parent()->layout_node(); if (layout_node && is(*end_node) && end_offset == end_node->length() && precedes_a_line_break(end_node)) { auto parent_white_space = layout_node->computed_values().white_space(); - - // FIXME: Find a way to get code points directly from the UTF-8 string - auto end_node_data = *end_node->text_content(); - auto utf16_code_units = MUST(AK::utf8_to_utf16(end_node_data)); - auto utf16_view = Utf16View { utf16_code_units }; - auto last_code_point = utf16_view.code_point_at(utf16_view.length_in_code_points() - 1); if (parent_white_space != CSS::WhiteSpace::Pre && parent_white_space != CSS::WhiteSpace::PreWrap - && last_code_point == 0x20) { + && end_node->text_content().value().ends_with_bytes(" "sv)) { // 1. Subtract one from end offset. --end_offset;