LibJS: Add fast path for Array.prototype.shift

Makes `MicroBench/array-prototype-shift.js` 100x faster on my machine.

Progress on https://github.com/LadybirdBrowser/ladybird/issues/5725
This commit is contained in:
Aliaksandr Kalenik
2025-08-08 03:46:16 +02:00
committed by Alexander Kalenik
parent 7c29db6ab0
commit 4b3a87eb14
Notes: github-actions[bot] 2025-08-08 16:11:20 +00:00
3 changed files with 42 additions and 25 deletions

View File

@@ -299,35 +299,36 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> Array::internal_get_own_property
return Object::internal_get_own_property(property_key);
}
bool Array::default_prototype_chain_intact() const
{
auto const& intrinsics = m_realm->intrinsics();
auto const* array_prototype = shape().prototype();
if (!array_prototype)
return false;
if (!array_prototype->indexed_properties().is_empty())
return false;
auto const& array_prototype_shape = shape().prototype()->shape();
if (intrinsics.default_array_prototype_shape().ptr() != &array_prototype_shape)
return false;
auto const* object_prototype = array_prototype_shape.prototype();
if (!object_prototype)
return false;
if (!object_prototype->indexed_properties().is_empty())
return false;
auto const& object_prototype_shape = array_prototype_shape.prototype()->shape();
if (intrinsics.default_object_prototype_shape().ptr() != &object_prototype_shape)
return false;
if (object_prototype_shape.prototype())
return false;
return true;
}
ThrowCompletionOr<bool> Array::internal_set(PropertyKey const& property_key, Value value, Value receiver, CacheablePropertyMetadata* cacheable_metadata, PropertyLookupPhase phase)
{
auto& vm = this->vm();
auto default_prototype_chain_intact = [&] {
auto const& intrinsics = m_realm->intrinsics();
auto* array_prototype = shape().prototype();
if (!array_prototype)
return false;
if (!array_prototype->indexed_properties().is_empty())
return false;
auto& array_prototype_shape = shape().prototype()->shape();
if (intrinsics.default_array_prototype_shape().ptr() != &array_prototype_shape)
return false;
auto* object_prototype = array_prototype_shape.prototype();
if (!object_prototype)
return false;
if (!object_prototype->indexed_properties().is_empty())
return false;
auto& object_prototype_shape = array_prototype_shape.prototype()->shape();
if (intrinsics.default_object_prototype_shape().ptr() != &object_prototype_shape)
return false;
if (object_prototype_shape.prototype())
return false;
return true;
};
VERIFY(receiver.is_object());
auto& receiver_object = receiver.as_object();