mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:37:36 +00:00
LibJS/Bytecode: Combine has_index() and get() in GetByVal and PutByVal
Since get() returns an empty Optional if the index is not present, we can combine these two into a single get() operation and save the cost of a virtual call.
This commit is contained in:
parent
55e9df4954
commit
8e04791480
1 changed files with 15 additions and 11 deletions
|
@ -123,12 +123,14 @@ inline ThrowCompletionOr<Value> get_by_value(VM& vm, Value base_value, Value pro
|
||||||
|
|
||||||
// For "non-typed arrays":
|
// For "non-typed arrays":
|
||||||
if (!object.may_interfere_with_indexed_property_access()
|
if (!object.may_interfere_with_indexed_property_access()
|
||||||
&& object_storage
|
&& object_storage) {
|
||||||
&& object_storage->has_index(index)) {
|
auto maybe_value = object_storage->get(index);
|
||||||
auto value = object_storage->get(index)->value;
|
if (maybe_value.has_value()) {
|
||||||
|
auto value = maybe_value->value;
|
||||||
if (!value.is_accessor())
|
if (!value.is_accessor())
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For typed arrays:
|
// For typed arrays:
|
||||||
if (object.is_typed_array()) {
|
if (object.is_typed_array()) {
|
||||||
|
@ -398,14 +400,16 @@ inline ThrowCompletionOr<void> put_by_value(VM& vm, Value base, Value property_k
|
||||||
// For "non-typed arrays":
|
// For "non-typed arrays":
|
||||||
if (storage
|
if (storage
|
||||||
&& storage->is_simple_storage()
|
&& storage->is_simple_storage()
|
||||||
&& !object.may_interfere_with_indexed_property_access()
|
&& !object.may_interfere_with_indexed_property_access()) {
|
||||||
&& storage->has_index(index)) {
|
auto maybe_value = storage->get(index);
|
||||||
auto existing_value = storage->get(index)->value;
|
if (maybe_value.has_value()) {
|
||||||
|
auto existing_value = maybe_value->value;
|
||||||
if (!existing_value.is_accessor()) {
|
if (!existing_value.is_accessor()) {
|
||||||
storage->put(index, value);
|
storage->put(index, value);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For typed arrays:
|
// For typed arrays:
|
||||||
if (object.is_typed_array()) {
|
if (object.is_typed_array()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue