mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibJS: Add common fast path for GetByValue from TypedArray
Same exact idea as the previous commit, just for GetByValue. :^)
This commit is contained in:
parent
51ac0d8821
commit
1bc58333f8
1 changed files with 23 additions and 7 deletions
|
@ -71,13 +71,29 @@ ThrowCompletionOr<Value> get_by_value(VM& vm, Value base_value, Value property_k
|
||||||
auto object = TRY(base_object_for_get(vm, base_value));
|
auto object = TRY(base_object_for_get(vm, base_value));
|
||||||
|
|
||||||
// OPTIMIZATION: Fast path for simple Int32 indexes in array-like objects.
|
// OPTIMIZATION: Fast path for simple Int32 indexes in array-like objects.
|
||||||
if (property_key_value.is_int32()
|
if (property_key_value.is_int32() && property_key_value.as_i32() >= 0) {
|
||||||
&& property_key_value.as_i32() >= 0
|
auto index = static_cast<u32>(property_key_value.as_i32());
|
||||||
&& !object->may_interfere_with_indexed_property_access()
|
|
||||||
&& object->indexed_properties().has_index(property_key_value.as_i32())) {
|
// For "non-typed arrays":
|
||||||
auto value = object->indexed_properties().get(property_key_value.as_i32())->value;
|
if (!object->may_interfere_with_indexed_property_access()
|
||||||
if (!value.is_accessor())
|
&& object->indexed_properties().has_index(index)) {
|
||||||
return value;
|
auto value = object->indexed_properties().get(index)->value;
|
||||||
|
if (!value.is_accessor())
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For typed arrays:
|
||||||
|
if (object->is_typed_array()) {
|
||||||
|
auto& typed_array = static_cast<TypedArrayBase&>(*object);
|
||||||
|
auto canonical_index = CanonicalIndex { CanonicalIndex::Type::Index, index };
|
||||||
|
switch (typed_array.kind()) {
|
||||||
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, Type) \
|
||||||
|
case TypedArrayBase::Kind::ClassName: \
|
||||||
|
return integer_indexed_element_get<Type>(typed_array, canonical_index);
|
||||||
|
JS_ENUMERATE_TYPED_ARRAYS
|
||||||
|
#undef __JS_ENUMERATE
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto property_key = TRY(property_key_value.to_property_key(vm));
|
auto property_key = TRY(property_key_value.to_property_key(vm));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue