mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +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:
parent
b953b5cc71
commit
7f3269fb02
Notes:
github-actions[bot]
2024-10-27 15:14:24 +00:00
Author: https://github.com/yyny Commit: https://github.com/LadybirdBrowser/ladybird/commit/7f3269fb025 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1998
1 changed files with 12 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue