mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibJS: Allow fast conversions between Uint8Array and Uint8ClampedArray
These two typed array kinds have the same exact underlying data type and differ only in how assignment works. We can allow them to take the fast paths for same-type conversions.
This commit is contained in:
parent
096eddfd5a
commit
4d7d8aa827
Notes:
github-actions[bot]
2025-12-01 14:14:12 +00:00
Author: https://github.com/awesomekling
Commit: 4d7d8aa827
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6982
Reviewed-by: https://github.com/gmta ✅
1 changed files with 6 additions and 2 deletions
|
|
@ -1493,7 +1493,9 @@ static ThrowCompletionOr<void> set_typed_array_from_typed_array(VM& vm, TypedArr
|
|||
auto limit = checked_limit.value();
|
||||
|
||||
// 23. If srcType is targetType, then
|
||||
if (source.element_name() == target.element_name()) {
|
||||
if (source.kind() == target.kind()
|
||||
|| (source.kind() == TypedArrayBase::Kind::Uint8Array && target.kind() == TypedArrayBase::Kind::Uint8ClampedArray)
|
||||
|| (source.kind() == TypedArrayBase::Kind::Uint8ClampedArray && target.kind() == TypedArrayBase::Kind::Uint8Array)) {
|
||||
// a. NOTE: The transfer must be performed in a manner that preserves the bit-level encoding of the source data.
|
||||
// b. Repeat, while targetByteIndex < limit,
|
||||
// i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, Uint8, true, Unordered).
|
||||
|
|
@ -1700,7 +1702,9 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::slice)
|
|||
// g. Let targetType be TypedArrayElementType(A).
|
||||
|
||||
// h. If srcType is targetType, then
|
||||
if (typed_array->element_name() == array->element_name()) {
|
||||
if (typed_array->kind() == array->kind()
|
||||
|| (typed_array->kind() == TypedArrayBase::Kind::Uint8Array && array->kind() == TypedArrayBase::Kind::Uint8ClampedArray)
|
||||
|| (typed_array->kind() == TypedArrayBase::Kind::Uint8ClampedArray && array->kind() == TypedArrayBase::Kind::Uint8Array)) {
|
||||
// i. NOTE: The transfer must be performed in a manner that preserves the bit-level encoding of the source data.
|
||||
|
||||
// ii. Let srcBuffer be O.[[ViewedArrayBuffer]].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue