[CSHARP-3565] LINQ3: Add AstExpression UseVarIfNotSimple factory method Created: 12/Apr/21 Updated: 28/Oct/23 Resolved: 04/Oct/21 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3 |
| Affects Version/s: | None |
| Fix Version/s: | 2.14.0 |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Robert Stam | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Epic Link: | CSHARP-2608 |
| Description |
|
Add the following helper method:
If the expression is "simple" return:
if the expression is not "simple" return:
where:
in other words, define a variable whose value is `expression` and create a reference to that variable. This helper method will be used whenever there is a possibly complex expression that is used more than once in a translation. Rather than allowing the complex expression to appear more than once in the translation, the complex expression is assigned to a variable and then the variable is referenced as many times as necessary. However, there is no need for the variable to be used when the expression is "simple". In that case the expression itself can be referenced multiple times with no performance or conceptual cost. The current definition of "simple" is: null, a constant, or a variable reference. Everything else is "not simple". Since `UseVarIfNotSimple` returns `null` if no variable is needed, change the behavior of `Let` to handle null vars differently and add a few new overloads:
For each overload, if all vars are `null` no `$let` is needed and the `@in` expression is returned directly. If one or more vars are not `null` then a `$let` is created defining whichever vars are not null.
|
| Comments |
| Comment by Robert Stam [ 12/Apr/21 ] |
|
Done but not reviewed |