mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 10:19:20 +00:00
AK: Don't iterate through entire String for String::ends_with
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This commit is contained in:
parent
233097c250
commit
23f3ecbe98
Notes:
github-actions[bot]
2025-04-28 14:51:37 +00:00
Author: https://github.com/shannonbooth
Commit: 23f3ecbe98
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4504
Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 9 additions and 4 deletions
|
@ -352,14 +352,19 @@ bool String::starts_with_bytes(StringView bytes, CaseSensitivity case_sensitivit
|
|||
|
||||
bool String::ends_with(u32 code_point) const
|
||||
{
|
||||
ASSERT(is_unicode(code_point));
|
||||
|
||||
if (is_empty())
|
||||
return false;
|
||||
|
||||
u32 last_code_point = 0;
|
||||
for (auto it = code_points().begin(); it != code_points().end(); ++it)
|
||||
last_code_point = *it;
|
||||
Array<u8, 4> code_point_as_utf8;
|
||||
size_t i = 0;
|
||||
|
||||
return last_code_point == code_point;
|
||||
size_t code_point_byte_length = UnicodeUtils::code_point_to_utf8(code_point, [&](auto byte) {
|
||||
code_point_as_utf8[i++] = static_cast<u8>(byte);
|
||||
});
|
||||
|
||||
return ends_with_bytes(StringView { code_point_as_utf8.data(), code_point_byte_length });
|
||||
}
|
||||
|
||||
bool String::ends_with_bytes(StringView bytes, CaseSensitivity case_sensitivity) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue