File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,13 @@ template <typename SorbetNode> class NodeAndExpr : public SorbetNode {
18
18
template <typename ... Args> NodeAndExpr (Args &&...args) : SorbetNode(std::forward<Args>(args)...) {}
19
19
20
20
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 );
24
28
}
25
29
26
30
// This method is intended to be called from the various `Translator` methods.
You can’t perform that action at this time.
0 commit comments