@@ -77,8 +77,7 @@ protected override Expression VisitSubQuery(SubQueryExpression expression)
77
77
private class SubQueryFromClauseExpander : RelinqExpressionVisitor
78
78
{
79
79
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 > ( ) ;
82
81
83
82
public bool Rewritten { get ; private set ; }
84
83
@@ -89,35 +88,36 @@ public SubQueryFromClauseExpander(QueryModel originalSubQueryModel)
89
88
90
89
protected override Expression VisitConditional ( ConditionalExpression node )
91
90
{
92
- if ( _depth >= 0 )
91
+ if ( _nominate . Count > 0 )
93
92
{
94
- _nominate [ _depth ] = false ;
93
+ _nominate . Pop ( ) ;
94
+ _nominate . Push ( false ) ;
95
95
}
96
96
97
97
var newTest = Visit ( node . Test ) ;
98
- _nominate . Insert ( ++ _depth , false ) ;
98
+ _nominate . Push ( false ) ;
99
99
var newTrue = Visit ( node . IfTrue ) ;
100
- if ( _nominate [ _depth ] )
100
+ if ( _nominate . Pop ( ) )
101
101
{
102
102
newTrue = BuildNewSubQuery ( newTrue ) ;
103
103
Rewritten = true ;
104
104
}
105
- _nominate . Insert ( _depth , false ) ;
105
+ _nominate . Push ( false ) ;
106
106
var newFalse = Visit ( node . IfFalse ) ;
107
- if ( _nominate [ _depth ] )
107
+ if ( _nominate . Pop ( ) )
108
108
{
109
109
newFalse = BuildNewSubQuery ( newFalse ) ;
110
110
Rewritten = true ;
111
111
}
112
- _nominate . RemoveAt ( _depth -- ) ;
113
112
return Expression . Condition ( newTest , newTrue , newFalse ) ;
114
113
}
115
114
116
115
protected override Expression VisitQuerySourceReference ( QuerySourceReferenceExpression expression )
117
116
{
118
- if ( _depth >= 0 )
117
+ if ( _nominate . Count > 0 )
119
118
{
120
- _nominate [ _depth ] = true ;
119
+ _nominate . Pop ( ) ;
120
+ _nominate . Push ( true ) ;
121
121
}
122
122
123
123
return base . VisitQuerySourceReference ( expression ) ;
0 commit comments