Skip to content

Commit e2da26e

Browse files
authored
Optimize DataTable.Columns - avoid unnecessary type casting (#320)
* Optimize `DataTable.Columns` - avoid unnecessary type casting * Constrants * Upgrade SQL Server * Explicit path to sqlcmd * Install MSSQL tools * Revert sqlcmd path
1 parent 9437347 commit e2da26e

File tree

8 files changed

+15
-44
lines changed

8 files changed

+15
-44
lines changed

.github/actions/mssql-fts/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04
1+
FROM mcr.microsoft.com/mssql/server:2022-CU16-ubuntu-22.04
22
USER root
33

44
ENV ACCEPT_EULA=Y \

.github/workflows/test-sql.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jobs:
2020
- name: Setup .NET
2121
uses: actions/setup-dotnet@v4
2222
with: { dotnet-version: 8 }
23+
- name: Setup MSSQL Tools
24+
uses: rails-sqlserver/setup-mssql@v1
25+
with:
26+
components: sqlcmd
27+
version: 2022
2328
- name: Build SQL Docker image with FTS feature
2429
run: docker build -t sql .github/actions/mssql-fts
2530
# - uses: ikalnytskyi/action-setup-postgres@v6

Orm/Xtensive.Orm/Core/Extensions/ArrayExtensions.cs

-18
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,6 @@ public static TNewItem[] Cast<TItem, TNewItem>(this TItem[] source)
3636
return items;
3737
}
3838

39-
/// <summary>
40-
/// Clones <paramref name="source"/> array with element conversion.
41-
/// </summary>
42-
/// <typeparam name="TItem">The type of item.</typeparam>
43-
/// <typeparam name="TNewItem">The type of item to convert to.</typeparam>
44-
/// <param name="source">The array to convert.</param>
45-
/// <param name="converter">A delegate that converts each element.</param>
46-
/// <returns>An array of converted elements.</returns>
47-
public static TNewItem[] Convert<TItem, TNewItem>(this TItem[] source, Converter<TItem, TNewItem> converter)
48-
{
49-
ArgumentNullException.ThrowIfNull(converter);
50-
var items = new TNewItem[source.Length];
51-
int i = 0;
52-
foreach (TItem item in source)
53-
items[i++] = converter(item);
54-
return items;
55-
}
56-
5739
/// <summary>
5840
/// Gets the index of first occurrence of the <paramref name="item"/>
5941
/// in the <paramref name="items"/> array, if found;

Orm/Xtensive.Orm/Sql/Model/DataTable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public PairedNodeCollection<DataTable, Index> Indexes
5757
/// Gets the columns.
5858
/// </summary>
5959
/// <value>The columns.</value>
60-
public abstract IList<DataTableColumn> Columns { get; }
60+
public abstract IReadOnlyList<DataTableColumn> Columns { get; }
6161

6262
#endregion
6363

Orm/Xtensive.Orm/Sql/Model/Domain.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,7 @@ public PairedNodeCollection<Domain, DomainConstraint> DomainConstraints
9090
/// Gets the constraints.
9191
/// </summary>
9292
/// <value>The constraints.</value>
93-
IList<Constraint> IConstrainable.Constraints
94-
{
95-
get
96-
{
97-
return constraints.ToArray().Convert(i => (Constraint)i);
98-
}
99-
}
93+
IReadOnlyList<Constraint> IConstrainable.Constraints => constraints;
10094

10195
#endregion
10296

@@ -142,4 +136,4 @@ internal Domain(Schema schema, string name, SqlValueType dataType, SqlExpression
142136

143137
#endregion
144138
}
145-
}
139+
}

Orm/Xtensive.Orm/Sql/Model/Interfaces/IConstrainable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public interface IConstrainable
1515
/// Gets the node constraints.
1616
/// </summary>
1717
/// <value>The constraints.</value>
18-
IList<Constraint> Constraints { get; }
18+
IReadOnlyList<Constraint> Constraints { get; }
1919
}
2020
}

Orm/Xtensive.Orm/Sql/Model/Table.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ public string Filegroup
148148
/// Gets the columns.
149149
/// </summary>
150150
/// <value>The columns.</value>
151-
public override IList<DataTableColumn> Columns
152-
{
153-
get { return TableColumns.ToArray().Convert(i => (DataTableColumn) i); }
154-
}
151+
public override IReadOnlyList<DataTableColumn> Columns => TableColumns;
155152

156153
#endregion
157154

@@ -161,10 +158,7 @@ public override IList<DataTableColumn> Columns
161158
/// Gets the node constraints.
162159
/// </summary>
163160
/// <value>The constraints.</value>
164-
IList<Constraint> IConstrainable.Constraints
165-
{
166-
get { return constraints.ToArray().Convert(i => (Constraint)i); }
167-
}
161+
IReadOnlyList<Constraint> IConstrainable.Constraints => constraints;
168162

169163
#endregion
170164

@@ -214,4 +208,4 @@ internal Table(Schema schema, string name)
214208

215209
#endregion
216210
}
217-
}
211+
}

Orm/Xtensive.Orm/Sql/Model/View.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ protected override void ChangeSchema(Schema value)
8989
/// Gets the columns.
9090
/// </summary>
9191
/// <value>The columns.</value>
92-
public override IList<DataTableColumn> Columns {
93-
get {
94-
return ViewColumns.ToArray().Convert(i => (DataTableColumn) i);
95-
}
96-
}
92+
public override IReadOnlyList<DataTableColumn> Columns => ViewColumns;
9793

9894
#endregion
9995

@@ -134,4 +130,4 @@ internal View(Schema schema, string name, SqlNative definition, CheckOptions che
134130

135131
#endregion
136132
}
137-
}
133+
}

0 commit comments

Comments
 (0)