Skip to content

Commit 6de248b

Browse files
fredericDelaportePleasantD
authored andcommitted
fixup! GH-1879 - Allow Coalesce and Conditional logic on entity properties and collections (LINQ)
Use a stack instead of a list with a pointer to "depth"
1 parent 14b67ac commit 6de248b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/NHibernate/Linq/ReWriters/SubQueryConditionalExpander.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ protected override Expression VisitSubQuery(SubQueryExpression expression)
7777
private class SubQueryFromClauseExpander : RelinqExpressionVisitor
7878
{
7979
private readonly QueryModel _originalSubQueryModel;
80-
private int _depth = -1;
81-
private readonly IList<bool> _nominate = new List<bool>();
80+
private readonly Stack<bool> _nominate = new Stack<bool>();
8281

8382
public bool Rewritten { get; private set; }
8483

@@ -89,35 +88,36 @@ public SubQueryFromClauseExpander(QueryModel originalSubQueryModel)
8988

9089
protected override Expression VisitConditional(ConditionalExpression node)
9190
{
92-
if (_depth >= 0)
91+
if (_nominate.Count > 0)
9392
{
94-
_nominate[_depth] = false;
93+
_nominate.Pop();
94+
_nominate.Push(false);
9595
}
9696

9797
var newTest = Visit(node.Test);
98-
_nominate.Insert(++_depth, false);
98+
_nominate.Push(false);
9999
var newTrue = Visit(node.IfTrue);
100-
if (_nominate[_depth])
100+
if (_nominate.Pop())
101101
{
102102
newTrue = BuildNewSubQuery(newTrue);
103103
Rewritten = true;
104104
}
105-
_nominate.Insert(_depth, false);
105+
_nominate.Push(false);
106106
var newFalse = Visit(node.IfFalse);
107-
if (_nominate[_depth])
107+
if (_nominate.Pop())
108108
{
109109
newFalse = BuildNewSubQuery(newFalse);
110110
Rewritten = true;
111111
}
112-
_nominate.RemoveAt(_depth--);
113112
return Expression.Condition(newTest, newTrue, newFalse);
114113
}
115114

116115
protected override Expression VisitQuerySourceReference(QuerySourceReferenceExpression expression)
117116
{
118-
if (_depth >= 0)
117+
if (_nominate.Count > 0)
119118
{
120-
_nominate[_depth] = true;
119+
_nominate.Pop();
120+
_nominate.Push(true);
121121
}
122122

123123
return base.VisitQuerySourceReference(expression);

0 commit comments

Comments
 (0)