mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibJS: Add fast paths for get and set on float typed arrays
This commit is contained in:
parent
3856dd946b
commit
ff791a63fc
Notes:
github-actions[bot]
2024-11-18 08:12:55 +00:00
Author: https://github.com/ananas-dev 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/ff791a63fca Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2411
1 changed files with 48 additions and 26 deletions
|
@ -1074,6 +1074,12 @@ inline ThrowCompletionOr<Value> get_by_value(VM& vm, Optional<IdentifierTableInd
|
|||
return fast_typed_array_get_element<i32>(typed_array, index);
|
||||
case TypedArrayBase::Kind::Uint8ClampedArray:
|
||||
return fast_typed_array_get_element<u8>(typed_array, index);
|
||||
case TypedArrayBase::Kind::Float16Array:
|
||||
return fast_typed_array_get_element<f16>(typed_array, index);
|
||||
case TypedArrayBase::Kind::Float32Array:
|
||||
return fast_typed_array_get_element<float>(typed_array, index);
|
||||
case TypedArrayBase::Kind::Float64Array:
|
||||
return fast_typed_array_get_element<double>(typed_array, index);
|
||||
default:
|
||||
// FIXME: Support more TypedArray kinds.
|
||||
break;
|
||||
|
@ -1312,7 +1318,8 @@ inline ThrowCompletionOr<void> put_by_value(VM& vm, Value base, Optional<Depreca
|
|||
auto& typed_array = static_cast<TypedArrayBase&>(object);
|
||||
auto canonical_index = CanonicalIndex { CanonicalIndex::Type::Index, index };
|
||||
|
||||
if (value.is_int32() && is_valid_integer_index(typed_array, canonical_index)) {
|
||||
if (is_valid_integer_index(typed_array, canonical_index)) {
|
||||
if (value.is_int32()) {
|
||||
switch (typed_array.kind()) {
|
||||
case TypedArrayBase::Kind::Uint8Array:
|
||||
fast_typed_array_set_element<u8>(typed_array, index, static_cast<u8>(value.as_i32()));
|
||||
|
@ -1336,9 +1343,24 @@ inline ThrowCompletionOr<void> put_by_value(VM& vm, Value base, Optional<Depreca
|
|||
fast_typed_array_set_element<u8>(typed_array, index, clamp(value.as_i32(), 0, 255));
|
||||
return {};
|
||||
default:
|
||||
// FIXME: Support more TypedArray kinds.
|
||||
break;
|
||||
}
|
||||
} else if (value.is_double()) {
|
||||
switch (typed_array.kind()) {
|
||||
case TypedArrayBase::Kind::Float16Array:
|
||||
fast_typed_array_set_element<f16>(typed_array, index, static_cast<f16>(value.as_double()));
|
||||
return {};
|
||||
case TypedArrayBase::Kind::Float32Array:
|
||||
fast_typed_array_set_element<float>(typed_array, index, static_cast<float>(value.as_double()));
|
||||
return {};
|
||||
case TypedArrayBase::Kind::Float64Array:
|
||||
fast_typed_array_set_element<double>(typed_array, index, value.as_double());
|
||||
return {};
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// FIXME: Support more TypedArray kinds.
|
||||
}
|
||||
|
||||
if (typed_array.kind() == TypedArrayBase::Kind::Uint32Array && value.is_integral_number()) {
|
||||
|
|
Loading…
Reference in a new issue