diff --git a/AK/Utf16View.cpp b/AK/Utf16View.cpp index 11b91e77861..c6cd17668b7 100644 --- a/AK/Utf16View.cpp +++ b/AK/Utf16View.cpp @@ -177,9 +177,9 @@ ErrorOr Utf16View::to_utf8(AllowInvalidCodeUnits allow_invalid_code_unit size_t Utf16View::length_in_code_points() const { - if (!m_length_in_code_points.has_value()) + if (m_length_in_code_points == NumericLimits::max()) m_length_in_code_points = calculate_length_in_code_points(); - return *m_length_in_code_points; + return m_length_in_code_points; } u16 Utf16View::code_unit_at(size_t index) const diff --git a/AK/Utf16View.h b/AK/Utf16View.h index f5b3f367751..2c69f89b6e7 100644 --- a/AK/Utf16View.h +++ b/AK/Utf16View.h @@ -135,7 +135,7 @@ private: size_t calculate_length_in_code_points() const; ReadonlySpan m_code_units; - NO_UNIQUE_ADDRESS mutable Optional m_length_in_code_points; + mutable size_t m_length_in_code_points { NumericLimits::max() }; }; }