mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
AK: Add ASCII fast path for Utf8View::contains
This also makes `Utf8View::trim` significantly faster, since most strings start and end with ASCII. (cherry picked from commit 7f3269fb025051c3eb2794b15e785b85b0ce37f3)
This commit is contained in:
1 parent
8011896224
commit
de1ecc17ce
1 file changed
+12
-3
+12
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user