Skip to content

Commit ce43b1a

Browse files
committed
Remove unnecessary deepCopy()
1 parent 3a56117 commit ce43b1a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: parser/prism/Translator.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ template <typename SorbetNode> class NodeAndExpr : public SorbetNode {
1818
template <typename... Args> NodeAndExpr(Args &&...args) : SorbetNode(std::forward<Args>(args)...) {}
1919

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

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

0 commit comments

Comments
 (0)