Skip to content

Commit

Permalink
feat(array): add reverse fast path
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandevp committed Oct 16, 2024
1 parent f5740ff commit e75d604
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,15 @@ impl ArrayPrototype {
}

fn reverse(agent: &mut Agent, this_value: Value, _: ArgumentsList) -> JsResult<Value> {
if let Value::Array(array) = this_value {
// Fast path: Array is dense and contains no descriptors. No JS
// functions can thus be called by shift.
if array.is_trivial(agent) && array.is_dense(agent) {
array.as_mut_slice(agent).reverse();
return Ok(array.into_value());
}
}

// 1. Let O be ? ToObject(this value).
let o = to_object(agent, this_value)?;
// 2. Let len be ? LengthOfArrayLike(O).
Expand Down

0 comments on commit e75d604

Please sign in to comment.