Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions core/engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,48 @@ impl Array {
.with_message("length + number of arguments exceeds the max safe integer limit")
.into());
}

if o.is_array() {
let mut o_borrow = o.borrow_mut();
let props = &mut o_borrow.properties_mut().indexed_properties;

let fast_path = match props {
IndexedProperties::DenseI32(dense) if dense.len() as u64 == len => {
Copy link
Copy Markdown
Author

@Exar04 Exar04 Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are iterating over values that will be added to array and converting it to type i32.
But what if we encounter string or f64? according to blog shared in issue, the type of array should get converted to lower type i.e DenseI32 -> DenseF64.
But we aren't doing that here (even before I added this code), is it getting handled somewhere else?

also if I am right about above, instead of getting out of match when encountering f64 instead of i32 it would be more performant to try again match.

something like this ->

fn main() {
    let mut b = 1;
    let a = loop {
        match b {
        1 => {
            b = 2;
            if b == 2{
                continue
            }
            break "one"
        },
        2 => break "two",
        _ => break "other",
    }
    };
    println!("{}", a);
}

but idk... its just a thought

let all_i32: Option<ThinVec<i32>> =
args.iter().map(JsValue::as_i32).collect();
if let Some(items) = all_i32 {
dense.splice(0..0, items);
true
} else {
false
}
}
IndexedProperties::DenseF64(dense) if dense.len() as u64 == len => {
let all_f64: Option<ThinVec<f64>> =
args.iter().map(JsValue::as_number).collect();
if let Some(items) = all_f64 {
dense.splice(0..0, items);
true
} else {
false
}
}
IndexedProperties::DenseElement(dense) if dense.len() as u64 == len => {
dense.splice(0..0, args.iter().cloned());
true
}
_ => false,
};

drop(o_borrow);

if fast_path {
let new_len = len + arg_count;
Self::set_length(&o, new_len, context)?;
return Ok(new_len.into());
}
}

// b. Let k be len.
let mut k = len;
// c. Repeat, while k > 0,
Expand Down