Skip to content

Commit

Permalink
perf(turbopack): Remove needless memory move ops (#74964)
Browse files Browse the repository at this point in the history
### What?

We don't need to move memories into the stacks of these functions because we are going to move these `JsValue` to the heap anyway.

### Why?

### How?
  • Loading branch information
kdy1 authored Jan 16, 2025
1 parent 9317e88 commit 46f3c5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions turbopack/crates/turbopack-ecmascript/src/analyzer/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,28 +457,28 @@ impl EvalContext {
left,
right,
..
}) => JsValue::equal(self.eval(left), self.eval(right)),
}) => JsValue::equal(Box::new(self.eval(left)), Box::new(self.eval(right))),

Expr::Bin(BinExpr {
op: op!("!="),
left,
right,
..
}) => JsValue::not_equal(self.eval(left), self.eval(right)),
}) => JsValue::not_equal(Box::new(self.eval(left)), Box::new(self.eval(right))),

Expr::Bin(BinExpr {
op: op!("==="),
left,
right,
..
}) => JsValue::strict_equal(self.eval(left), self.eval(right)),
}) => JsValue::strict_equal(Box::new(self.eval(left)), Box::new(self.eval(right))),

Expr::Bin(BinExpr {
op: op!("!=="),
left,
right,
..
}) => JsValue::strict_not_equal(self.eval(left), self.eval(right)),
}) => JsValue::strict_not_equal(Box::new(self.eval(left)), Box::new(self.eval(right))),

&Expr::Cond(CondExpr {
box ref cons,
Expand Down Expand Up @@ -1670,7 +1670,7 @@ impl VisitAstPath for Analyzer<'_> {
{
let mut ast_path =
ast_path.with_guard(AstParentNodeRef::ForOfStmt(n, ForOfStmtField::Left));
self.current_value = Some(JsValue::iterated(array));
self.current_value = Some(JsValue::iterated(Box::new(array)));
self.visit_for_head(&n.left, &mut ast_path);
}

Expand Down
28 changes: 14 additions & 14 deletions turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,43 +863,43 @@ impl JsValue {
)
}

pub fn iterated(iterable: JsValue) -> Self {
Self::Iterated(1 + iterable.total_nodes(), Box::new(iterable))
pub fn iterated(iterable: Box<JsValue>) -> Self {
Self::Iterated(1 + iterable.total_nodes(), iterable)
}

pub fn equal(a: JsValue, b: JsValue) -> Self {
pub fn equal(a: Box<JsValue>, b: Box<JsValue>) -> Self {
Self::Binary(
1 + a.total_nodes() + b.total_nodes(),
Box::new(a),
a,
BinaryOperator::Equal,
Box::new(b),
b,
)
}

pub fn not_equal(a: JsValue, b: JsValue) -> Self {
pub fn not_equal(a: Box<JsValue>, b: Box<JsValue>) -> Self {
Self::Binary(
1 + a.total_nodes() + b.total_nodes(),
Box::new(a),
a,
BinaryOperator::NotEqual,
Box::new(b),
b,
)
}

pub fn strict_equal(a: JsValue, b: JsValue) -> Self {
pub fn strict_equal(a: Box<JsValue>, b: Box<JsValue>) -> Self {
Self::Binary(
1 + a.total_nodes() + b.total_nodes(),
Box::new(a),
a,
BinaryOperator::StrictEqual,
Box::new(b),
b,
)
}

pub fn strict_not_equal(a: JsValue, b: JsValue) -> Self {
pub fn strict_not_equal(a: Box<JsValue>, b: Box<JsValue>) -> Self {
Self::Binary(
1 + a.total_nodes() + b.total_nodes(),
Box::new(a),
a,
BinaryOperator::StrictNotEqual,
Box::new(b),
b,
)
}

Expand Down

0 comments on commit 46f3c5c

Please sign in to comment.