mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibJS: Fast path for TypedArray.slice()
We now try to do a bulk memcpy() when possible. This is significantly faster than going byte-at-a-time.
This commit is contained in:
parent
94fc8c47c0
commit
99bef81d09
Notes:
github-actions[bot]
2025-12-01 14:14:00 +00:00
Author: https://github.com/awesomekling
Commit: 99bef81d09
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6982
Reviewed-by: https://github.com/gmta ✅
1 changed files with 17 additions and 10 deletions
|
|
@ -1740,19 +1740,26 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::slice)
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ix. Repeat, while targetByteIndex < limit,
|
// OPTIMIZATION: If the buffers are not detached and not shared, we can do a single bulk copy.
|
||||||
while (target_byte_index < limit) {
|
if (!target_buffer.is_detached() && !target_buffer.is_shared_array_buffer()
|
||||||
// 1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, uint8, true, unordered).
|
&& !source_buffer.is_detached() && !source_buffer.is_shared_array_buffer()
|
||||||
auto value = source_buffer.get_value<u8>(source_byte_index.value(), true, ArrayBuffer::Unordered);
|
&& &target_buffer.buffer() != &source_buffer.buffer()) {
|
||||||
|
target_buffer.buffer().overwrite(target_byte_index, source_buffer.buffer().data() + source_byte_index.value(), limit.value() - target_byte_index);
|
||||||
|
} else {
|
||||||
|
// ix. Repeat, while targetByteIndex < limit,
|
||||||
|
while (target_byte_index < limit) {
|
||||||
|
// 1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, uint8, true, unordered).
|
||||||
|
auto value = source_buffer.get_value<u8>(source_byte_index.value(), true, ArrayBuffer::Unordered);
|
||||||
|
|
||||||
// 2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered).
|
// 2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered).
|
||||||
target_buffer.set_value<u8>(target_byte_index, value, true, ArrayBuffer::Unordered);
|
target_buffer.set_value<u8>(target_byte_index, value, true, ArrayBuffer::Unordered);
|
||||||
|
|
||||||
// 3. Set srcByteIndex to srcByteIndex + 1.
|
// 3. Set srcByteIndex to srcByteIndex + 1.
|
||||||
++source_byte_index;
|
++source_byte_index;
|
||||||
|
|
||||||
// 4. Set targetByteIndex to targetByteIndex + 1.
|
// 4. Set targetByteIndex to targetByteIndex + 1.
|
||||||
++target_byte_index;
|
++target_byte_index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// i. Else,
|
// i. Else,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue