Skip to content

Commit e2b4e29

Browse files
committed
Remove unnecessary deepCopy()
1 parent 59a4d47 commit e2b4e29

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

parser/prism/Translator.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ template <typename SorbetNode> class NodeAndExpr : public SorbetNode {
2323
template <typename... Args> NodeAndExpr(Args &&...args) : SorbetNode(std::forward<Args>(args)...) {}
2424

2525
virtual ast::ExpressionPtr getCachedDesugaredExpr() {
26-
if (this->desugaredExpr == nullptr)
27-
return nullptr;
28-
return this->desugaredExpr.deepCopy();
26+
// We know each `NodeAndExpr` object's `getCachedDesugaredExpr()` will be called at most once, either:
27+
// 1. When its parent node is being translated below, and this value is used to create that parent's expr.
28+
// 2. When this node is visted by `node2TreeImpl` in `Runner.cc`, and this value is used in the fast-path.
29+
//
30+
// Because of this, we don't need to make any copies here. Just move this value out,
31+
// and exclusive ownership to the caller.
32+
return std::move(this->desugaredExpr);
2933
}
3034

3135
// This method is intended to be called from the various `Translator` methods.

0 commit comments

Comments
 (0)