Skip to content

Commit b951fa1

Browse files
committed
Preallocate 8 column names instead of 1
+ TupleDescriptor parameters of method declared as in paramters
1 parent 3f5b130 commit b951fa1

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

Orm/Xtensive.Orm/Orm/Providers/TemporaryTables/TemporaryTableManager.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ public class TemporaryTableManager : DomainBoundHandler
2424
private const string TableNamePattern = "Tmp_{0}";
2525
private const string ColumnNamePattern = "C{0}";
2626

27-
// Preallocated array of 1 column name
28-
private static readonly string[] ColumnNames1 = new[] { string.Format(ColumnNamePattern, 0) };
27+
// Preallocated array of 8 column names
28+
// to get parts of it
29+
private readonly string[] columnNames8 = new[] {
30+
string.Format(ColumnNamePattern, 0), string.Format(ColumnNamePattern, 1),
31+
string.Format(ColumnNamePattern, 2), string.Format(ColumnNamePattern, 3),
32+
string.Format(ColumnNamePattern, 4), string.Format(ColumnNamePattern, 5),
33+
string.Format(ColumnNamePattern, 6), string.Format(ColumnNamePattern, 7),
34+
};
2935

3036
private TemporaryTableBackEnd backEnd;
3137
private bool useTruncate;
@@ -42,7 +48,7 @@ public class TemporaryTableManager : DomainBoundHandler
4248
/// <param name="name">The name of the temporary table.</param>
4349
/// <param name="source">The source.</param>
4450
/// <returns>Built descriptor.</returns>
45-
public TemporaryTableDescriptor BuildDescriptor(ModelMapping modelMapping, string name, TupleDescriptor source)
51+
public TemporaryTableDescriptor BuildDescriptor(ModelMapping modelMapping, string name, in TupleDescriptor source)
4652
{
4753
return BuildDescriptor(modelMapping, name, source, null);
4854
}
@@ -55,7 +61,7 @@ public TemporaryTableDescriptor BuildDescriptor(ModelMapping modelMapping, strin
5561
/// <param name="source">The source.</param>
5662
/// <param name="fieldNames">The names of field in temporary table.</param>
5763
/// <returns>Built descriptor.</returns>
58-
public TemporaryTableDescriptor BuildDescriptor(ModelMapping modelMapping, string name, TupleDescriptor source, string[] fieldNames)
64+
public TemporaryTableDescriptor BuildDescriptor(ModelMapping modelMapping, string name, in TupleDescriptor source, string[] fieldNames)
5965
{
6066
EnsureTemporaryTablesSupported();
6167

@@ -70,14 +76,14 @@ public TemporaryTableDescriptor BuildDescriptor(ModelMapping modelMapping, strin
7076
? new Collation(schema, modelMapping.TemporaryTableCollation)
7177
: null;
7278

73-
fieldNames ??= BuildFieldNames(source);
79+
var resultFieldNames = fieldNames ?? BuildFieldNamesAsSegment(source);
7480

7581
var typeMappings = source
7682
.Select(driver.GetTypeMapping)
7783
.ToArray();
7884

7985
// table
80-
var table = CreateTemporaryTable(schema, name, source, typeMappings, fieldNames, collation);
86+
var table = CreateTemporaryTable(schema, name, source, typeMappings, resultFieldNames, collation);
8187
var tableRef = SqlDml.TableRef(table);
8288

8389
// select statement
@@ -163,16 +169,20 @@ private void EnsureTemporaryTablesSupported()
163169
throw new NotSupportedException(Strings.ExTemporaryTablesAreNotSupportedByCurrentStorage);
164170
}
165171

166-
private string[] BuildFieldNames(in TupleDescriptor source) =>
167-
source.Count == 1
168-
? ColumnNames1
172+
private ArraySegment<string> BuildFieldNamesAsSegment(TupleDescriptor source)
173+
{
174+
var count = source.Count;
175+
return count <= 8
176+
? new ArraySegment<string>(columnNames8, 0, count)
169177
: Enumerable.Range(0, source.Count)
170178
.Select(i => string.Format(ColumnNamePattern, i))
171179
.ToArray();
180+
}
172181

173-
private Table CreateTemporaryTable(Schema schema, string name, TupleDescriptor source, TypeMapping[] typeMappings, string[] fieldNames, Collation collation)
182+
private Table CreateTemporaryTable(Schema schema,
183+
string tempTableName, in TupleDescriptor source, TypeMapping[] typeMappings, ArraySegment<string> fieldNames, Collation collation)
174184
{
175-
var tableName = Handlers.NameBuilder.ApplyNamingRules(string.Format(TableNamePattern, name));
185+
var tableName = Handlers.NameBuilder.ApplyNamingRules(string.Format(TableNamePattern, tempTableName));
176186
var table = backEnd.CreateTemporaryTable(schema, tableName);
177187

178188
if (source.Count > 0) {

0 commit comments

Comments
 (0)