mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Add ASCII fast path for Utf8View::contains
This also makes `Utf8View::trim` significantly faster, since most strings start and end with ASCII.
This commit is contained in:
committed by
Andreas Kling
parent
b953b5cc71
commit
7f3269fb02
@@ -104,10 +104,19 @@ bool Utf8View::starts_with(Utf8View const& start) const
|
||||
|
||||
bool Utf8View::contains(u32 needle) const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user