Skip to content

Commit 4f784dd

Browse files
authored
Optimize TranslatorContext (#261)
* Optimize `TranslatorContext` * ArgumentNullException.ThrowIfNull() * Fix AliasGenerators * in arg * in arg * Optimize `CompositePostCompiler` * Optimize ColumnIndexMapping * Optimize NodeCollection * Optimize BuildKeyInfo()
1 parent b6ae044 commit 4f784dd

File tree

23 files changed

+87
-175
lines changed

23 files changed

+87
-175
lines changed

Orm/Xtensive.Orm.Firebird/Orm.Providers.Firebird/SqlCompiler.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88

99
namespace Xtensive.Orm.Providers.Firebird
1010
{
11-
internal class SqlCompiler : Providers.SqlCompiler
12-
{
13-
// Constructors
14-
15-
public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
16-
: base(handlers, configuration)
17-
{
18-
}
19-
}
20-
}
11+
internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration)
12+
: Providers.SqlCompiler(handlers, configuration);
13+
}

Orm/Xtensive.Orm.MySql/Orm.Providers.MySql/SqlCompiler.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99

1010
namespace Xtensive.Orm.Providers.MySql
1111
{
12-
internal class SqlCompiler : Providers.SqlCompiler
13-
{
14-
// Constructors
15-
16-
public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
17-
: base(handlers, configuration)
18-
{
19-
}
20-
}
21-
}
12+
internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration)
13+
: Providers.SqlCompiler(handlers, configuration);
14+
}

Orm/Xtensive.Orm.Oracle/Orm.Providers.Oracle/SqlCompiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ protected override SqlExpression ProcessAggregate(SqlProvider source, IReadOnlyL
3737

3838
// Constructors
3939

40-
public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
40+
public SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration)
4141
: base(handlers, configuration)
4242
{
4343
}
4444
}
45-
}
45+
}

Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ protected override IEnumerable<Type> GetProviderCompilerContainers()
3535
});
3636
}
3737
}
38-
}
38+
}

Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected override SqlExpression ProcessAggregate(SqlProvider source, IReadOnlyL
6262
return result;
6363
}
6464

65-
public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
65+
public SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration)
6666
: base(handlers, configuration)
6767
{
6868
}

Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/DomainHandler.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ namespace Xtensive.Orm.Providers.SqlServer
1717
public class DomainHandler : Providers.DomainHandler
1818
{
1919
/// <inheritdoc/>
20-
protected override ICompiler CreateCompiler(CompilerConfiguration configuration)
21-
{
22-
return new SqlCompiler(Handlers, configuration);
23-
}
20+
protected override ICompiler CreateCompiler(CompilerConfiguration configuration) => new SqlCompiler(Handlers, configuration);
2421

2522
/// <inheritdoc/>
2623
protected override SearchConditionCompiler CreateSearchConditionVisitor()
@@ -30,4 +27,4 @@ protected override SearchConditionCompiler CreateSearchConditionVisitor()
3027
return new SearchConditionCompilerV11();
3128
}
3229
}
33-
}
30+
}

Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/SqlCompiler.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Xtensive.Orm.Providers.SqlServer
1717
{
18-
internal class SqlCompiler : Providers.SqlCompiler
18+
internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) : Providers.SqlCompiler(handlers, configuration)
1919
{
2020
private static readonly Type ByteType = typeof(byte);
2121
private static readonly Type Int16Type = typeof(short);
@@ -149,12 +149,5 @@ private bool ShouldCastDueType(Type type)
149149
|| type == DecimalType
150150
|| type == FloatType;
151151
}
152-
153-
// Constructors
154-
155-
public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
156-
: base(handlers, configuration)
157-
{
158-
}
159152
}
160153
}

Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v09/ColumnResolver.cs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,35 @@
44
// Created by: Dmitri Maximov
55
// Created: 2009.08.12
66

7-
using System;
8-
using System.Collections.Generic;
9-
using System.Linq;
107
using Xtensive.Sql.Model;
118

129
namespace Xtensive.Sql.Drivers.SqlServer.v09
1310
{
14-
internal sealed class ColumnResolver
11+
internal sealed class ColumnResolver(DataTable table)
1512
{
16-
public DataTable Table;
17-
private List<ColumnIndexMapping> columnMappings;
18-
19-
private class ColumnIndexMapping
20-
{
21-
public readonly int DbIndex;
22-
public readonly int ModelIndex;
23-
24-
public ColumnIndexMapping(int dbIndex, int modelIndex)
25-
{
26-
DbIndex = dbIndex;
27-
ModelIndex = modelIndex;
28-
}
29-
}
13+
private readonly record struct ColumnIndexMapping(int DbIndex, int ModelIndex, bool IsValid);
3014

31-
public void RegisterColumnMapping(int dbIndex, int modelIndex)
32-
{
33-
if (columnMappings == null)
34-
columnMappings = new List<ColumnIndexMapping>(1);
15+
public DataTable Table = table;
16+
private List<ColumnIndexMapping> columnMappings;
3517

36-
columnMappings.Add(new ColumnIndexMapping(dbIndex, modelIndex));
37-
}
18+
public void RegisterColumnMapping(int dbIndex, int modelIndex) =>
19+
(columnMappings ??= new(1)).Add(new ColumnIndexMapping(dbIndex, modelIndex, true));
3820

3921
public DataTableColumn GetColumn(int dbIndex)
4022
{
4123
int modelIndex = dbIndex-1;
42-
var view = Table as View;
43-
if (view != null)
24+
if (Table is View view)
4425
return view.ViewColumns[modelIndex];
4526

4627
var table = (Table)Table;
4728
if (columnMappings == null)
4829
return table.TableColumns[modelIndex];
4930

50-
var mapping = columnMappings.Where(item => item.DbIndex==dbIndex).FirstOrDefault();
51-
if (mapping != null)
31+
var mapping = columnMappings.FirstOrDefault(item => item.DbIndex==dbIndex);
32+
if (mapping != default)
5233
return table.TableColumns[mapping.ModelIndex];
5334

5435
throw new ArgumentOutOfRangeException("dbIndex");
5536
}
56-
57-
public ColumnResolver(DataTable table)
58-
{
59-
Table = table;
60-
}
6137
}
62-
}
38+
}

Orm/Xtensive.Orm.Sqlite/Orm.Providers.Sqlite/SqlCompiler.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88

99
namespace Xtensive.Orm.Providers.Sqlite
1010
{
11-
internal class SqlCompiler : Providers.SqlCompiler
12-
{
13-
14-
// Constructors
15-
16-
public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
17-
: base(handlers, configuration)
18-
{
19-
}
20-
}
21-
}
11+
internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration)
12+
: Providers.SqlCompiler(handlers, configuration);
13+
}

Orm/Xtensive.Orm/Core/AliasGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Xtensive.Core
1212
/// Universal alias generator.
1313
/// </summary>
1414
[Serializable]
15-
public sealed class AliasGenerator
15+
public struct AliasGenerator
1616
{
1717
/// <summary>
1818
/// Default alias template. Value is "{0}{1}". Where {0} - template parameter for prefix and {1} - template parameter for suffix.
@@ -93,7 +93,7 @@ public static AliasGenerator Create(string[] overriddenPrefixes, string aliasTem
9393

9494
// Constructors
9595

96-
private AliasGenerator()
96+
public AliasGenerator()
9797
: this (DefaultAliasTemplate)
9898
{}
9999

@@ -111,4 +111,4 @@ private AliasGenerator(string[] prefixes, string aliasTemplate)
111111
this.aliasTemplate = aliasTemplate;
112112
}
113113
}
114-
}
114+
}

0 commit comments

Comments
 (0)