File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments