diff --git a/AK/Utf8View.cpp b/AK/Utf8View.cpp index 151b5918c46..edc50e62bae 100644 --- a/AK/Utf8View.cpp +++ b/AK/Utf8View.cpp @@ -104,10 +104,19 @@ bool Utf8View::starts_with(Utf8View const& start) const bool Utf8View::contains(u32 needle) const { - for (u32 code_point : *this) { - if (code_point == needle) - return true; + if (needle <= 0x7f) { + // OPTIMIZATION: Fast path for ASCII + for (u8 code_point : as_string()) { + if (code_point == needle) + return true; + } + } else { + for (u32 code_point : *this) { + if (code_point == needle) + return true; + } } + return false; }