Truly independent web browser
LibJS: Make room for the elements of an array literal up front
Andreas Kling7571e8957dcf
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rsindex 57aad9510e6..39c08e6d495 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs@@ -1465,6 +1465,11 @@ impl Generator<'_> {}}+ /// Makes room for `count` more values, which are about to come.+ pub(super) fn reserve_values(&mut self, count: usize) {+ self.context.stream.values.reserve(count);+ }+#[inline(always)]pub(super) fn push_value(&mut self, operand: Operand, first_temporary: u32) {self.context.stream.values.push(Val {@@ -3570,6 +3575,7 @@ impl Generator<'_> {use crate::bytecode::constant_fold::*;let mut values = std::mem::take(&mut self.context.primitive_values);values.clear();+ values.reserve(elements.len());for &element in elements {let value = match self.context.constants.get(element) {Some(ConstantValue::Number(number)) => nanboxed_number(*number),diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/sweep.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/sweep.rsindex 9afa19c8491..5ccaa6e9c39 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/sweep.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/sweep.rs@@ -474,6 +474,10 @@ impl Generator<'_> {row = a as usize + 1;continue;}+ // NB: The elements of an array literal come next, each as a value, which can be very many.+ if a == 0 {+ self.reserve_values(b as usize);+ }}other if (tag::BINARY_BASE..tag::MARK_CALLEE).contains(&other) => {match crate::ast::SyntaxTree::binary_operator(other) {diff --git a/Libraries/LibJS/Rust/src/parser/expr.rs b/Libraries/LibJS/Rust/src/parser/expr.rsindex c32bbd4c46e..bddfdf1c337 100644--- a/Libraries/LibJS/Rust/src/parser/expr.rs+++ b/Libraries/LibJS/Rust/src/parser/expr.rs@@ -1058,6 +1058,11 @@ impl<U: Unit> Parser<'_, U> {}}self.expect(T::RBracket);+ if subtree != NONE {+ // NB: The mark of an array is not that of a subtree that a sweep goes by. It tells the sweep how many+ // elements come.+ self.ast.b[subtree as usize] = (self.scratch.len() - mark) as u32;+ }let list = self.finish_list(mark);let array_tag = if self.marks && has_spread {tag::ARRAY_SPREAD