mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibJS: Add fast path for TypedArrayPrototype.copyWithin()
This can be a simple memmove() in the most common cases. Shaves 500ms of load time off of https://terminal.shop/api
This commit is contained in:
parent
3d7c5115d8
commit
ada198bee0
Notes:
github-actions[bot]
2025-07-17 06:51:12 +00:00
Author: https://github.com/awesomekling
Commit: ada198bee0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5477
Reviewed-by: https://github.com/gmta ✅
1 changed files with 19 additions and 0 deletions
|
@ -383,6 +383,25 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::copy_within)
|
|||
direction = 1;
|
||||
}
|
||||
|
||||
// OPTIMIZATION: Fast path for non-shared ArrayBuffers that are not detached and have enough space to perform the copy with memmove.
|
||||
if (!buffer->is_shared_array_buffer()) {
|
||||
Checked<size_t> from_end = from_byte_index;
|
||||
from_end += count_bytes;
|
||||
Checked<size_t> to_end = to_byte_index;
|
||||
to_end += count_bytes;
|
||||
|
||||
if (!from_end.has_overflow()
|
||||
&& !to_end.has_overflow()
|
||||
&& from_end.value() <= buffer_byte_limit
|
||||
&& to_end.value() <= buffer_byte_limit) {
|
||||
auto* base = buffer->buffer().data();
|
||||
void const* src = base + from_byte_index;
|
||||
void* dst = base + to_byte_index;
|
||||
memmove(dst, src, count_bytes);
|
||||
return typed_array;
|
||||
}
|
||||
}
|
||||
|
||||
// n. Repeat, while countBytes > 0,
|
||||
while (count_bytes > 0) {
|
||||
// i. If fromByteIndex < bufferByteLimit and toByteIndex < bufferByteLimit, then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue