Skip to content

Commit

Permalink
Remove unnecessary deepCopy()
Browse files Browse the repository at this point in the history
  • Loading branch information
amomchilov committed Sep 18, 2024
1 parent 3a56117 commit ce43b1a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ template <typename SorbetNode> class NodeAndExpr : public SorbetNode {
template <typename... Args> NodeAndExpr(Args &&...args) : SorbetNode(std::forward<Args>(args)...) {}

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

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

0 comments on commit ce43b1a

Please sign in to comment.