5
5
// Created: 2012.05.18
6
6
7
7
using System . Collections . Generic ;
8
- using System . Collections . ObjectModel ;
9
8
using Xtensive . Sql . Dml ;
10
9
11
10
namespace Xtensive . Sql . Compiler
12
11
{
13
- internal sealed class JoinSequence
12
+ internal readonly record struct JoinSequence
13
+ (
14
+ SqlTable Pivot ,
15
+ IReadOnlyList < SqlTable > Tables ,
16
+ IReadOnlyList < SqlJoinType > JoinTypes ,
17
+ IReadOnlyList < SqlExpression > Conditions
18
+ )
14
19
{
15
- public SqlTable Pivot { get ; private set ; }
16
-
17
- public IList < SqlTable > Tables { get ; private set ; }
18
-
19
- public IList < SqlJoinType > JoinTypes { get ; private set ; }
20
-
21
- public IList < SqlExpression > Conditions { get ; private set ; }
22
-
23
20
public static JoinSequence Build ( SqlJoinedTable root )
24
21
{
25
- var joins = new List < SqlJoinExpression > ( ) ;
22
+ var joins = new List < SqlJoinExpression > ( 1 ) ;
26
23
Traverse ( root , joins ) ;
27
24
28
- var result = new JoinSequence ( ) ;
25
+ List < SqlTable > tables = new ( ) ;
26
+ List < SqlJoinType > joinTypes = new ( ) ;
27
+ List < SqlExpression > conditions = new ( ) ;
29
28
30
29
foreach ( var item in joins ) {
31
- if ( ! ( item . Left is SqlJoinedTable ) )
32
- result . Tables . Add ( item . Left ) ;
33
- if ( ! ( item . Right is SqlJoinedTable ) )
34
- result . Tables . Add ( item . Right ) ;
35
- result . JoinTypes . Add ( item . JoinType ) ;
36
- result . Conditions . Add ( item . Expression ) ;
30
+ var left = item . Left ;
31
+ if ( ! ( left is SqlJoinedTable ) )
32
+ tables . Add ( left ) ;
33
+ var right = item . Right ;
34
+ if ( ! ( right is SqlJoinedTable ) )
35
+ tables . Add ( right ) ;
36
+ joinTypes . Add ( item . JoinType ) ;
37
+ conditions . Add ( item . Expression ) ;
37
38
}
38
39
39
- var pivot = result . Tables [ 0 ] ;
40
- result . Pivot = pivot ;
41
- result . Tables . RemoveAt ( 0 ) ;
42
-
43
- result . Tables = new ReadOnlyCollection < SqlTable > ( result . Tables ) ;
44
- result . JoinTypes = new ReadOnlyCollection < SqlJoinType > ( result . JoinTypes ) ;
45
- result . Conditions = new ReadOnlyCollection < SqlExpression > ( result . Conditions ) ;
46
-
47
- return result ;
40
+ var pivot = tables [ 0 ] ;
41
+ tables . RemoveAt ( 0 ) ;
42
+ return new ( pivot , tables , joinTypes , conditions ) ;
48
43
}
49
44
50
- private static void Traverse ( SqlJoinedTable root , ICollection < SqlJoinExpression > output )
45
+ private static void Traverse ( SqlJoinedTable root , List < SqlJoinExpression > output )
51
46
{
52
- var left = root . JoinExpression . Left ;
53
- var joinedLeft = left as SqlJoinedTable ;
54
- if ( joinedLeft != null )
47
+ var joinExpression = root . JoinExpression ;
48
+ if ( joinExpression . Left is SqlJoinedTable joinedLeft ) {
55
49
Traverse ( joinedLeft , output ) ;
50
+ }
56
51
57
- output . Add ( root . JoinExpression ) ;
52
+ output . Add ( joinExpression ) ;
58
53
59
- var right = root . JoinExpression . Right ;
60
- var joinedRight = right as SqlJoinedTable ;
61
- if ( joinedRight != null )
54
+ if ( joinExpression . Right is SqlJoinedTable joinedRight ) {
62
55
Traverse ( joinedRight , output ) ;
63
- }
64
-
65
-
66
- // Constructors
67
-
68
- private JoinSequence ( )
69
- {
70
- Tables = new List < SqlTable > ( ) ;
71
- JoinTypes = new List < SqlJoinType > ( ) ;
72
- Conditions = new List < SqlExpression > ( ) ;
56
+ }
73
57
}
74
58
}
75
59
}
0 commit comments