AK: Make more use of lazily calculated code point count in Utf16View

In 0c93a07fb1, a lazily calculated code
point count was introduced but was not used in all places where we need
that count. No functional changes.
This commit is contained in:
Jelle Raaijmakers 2025-06-11 11:35:28 +02:00 committed by Jelle Raaijmakers
commit 0d543b604b
Notes: github-actions[bot] 2025-06-13 13:10:34 +00:00

View file

@ -204,7 +204,7 @@ u32 Utf16View::code_point_at(size_t index) const
size_t Utf16View::code_point_offset_of(size_t code_unit_offset) const
{
if (m_length_in_code_points == m_code_units.size()) // Fast path: all code points are one code unit.
if (length_in_code_points() == length_in_code_units()) // Fast path: all code points are one code unit.
return code_unit_offset;
size_t code_point_offset = 0;
@ -222,7 +222,7 @@ size_t Utf16View::code_point_offset_of(size_t code_unit_offset) const
size_t Utf16View::code_unit_offset_of(size_t code_point_offset) const
{
if (m_length_in_code_points == m_code_units.size()) // Fast path: all code points are one code unit.
if (length_in_code_points() == length_in_code_units()) // Fast path: all code points are one code unit.
return code_point_offset;
size_t code_unit_offset = 0;
@ -259,7 +259,7 @@ Utf16View Utf16View::unicode_substring_view(size_t code_point_offset, size_t cod
if (code_point_length == 0)
return {};
if (m_length_in_code_points == m_code_units.size()) // Fast path: all code points are one code unit.
if (length_in_code_points() == length_in_code_units()) // Fast path: all code points are one code unit.
return substring_view(code_point_offset, code_point_length);
auto code_unit_offset_of = [&](Utf16CodePointIterator const& it) { return it.m_ptr - begin_ptr(); };