Skip to content

Commit da2bfd3

Browse files
Innocuous changes. Some array allocation removal.
1 parent 0bf765b commit da2bfd3

5 files changed

Lines changed: 25 additions & 18 deletions

File tree

ExpressiveCommandBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public T ExecuteReturn<T>()
486486
/// <param name="behavior">The command behavior for once the command the reader is complete.</param>
487487
public void ExecuteReader(Action<IDataReader> handler, CommandBehavior behavior = CommandBehavior.Default)
488488
{
489-
if (Connection == null || Connection.State == ConnectionState.Closed) behavior = behavior | CommandBehavior.CloseConnection;
489+
if (Connection == null || Connection.State == ConnectionState.Closed) behavior |= CommandBehavior.CloseConnection;
490490
Execute(command => command.ExecuteReader(handler, behavior));
491491
}
492492

@@ -499,7 +499,7 @@ public void ExecuteReader(Action<IDataReader> handler, CommandBehavior behavior
499499
/// <returns>The result of the transform.</returns>
500500
public T ExecuteReader<T>(Func<IDataReader, T> transform, CommandBehavior behavior = CommandBehavior.Default)
501501
{
502-
if (Connection == null || Connection.State == ConnectionState.Closed) behavior = behavior | CommandBehavior.CloseConnection;
502+
if (Connection == null || Connection.State == ConnectionState.Closed) behavior |= CommandBehavior.CloseConnection;
503503
return Execute(command => command.ExecuteReader(transform, behavior));
504504
}
505505

Extensions.Dataflow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static async Task ToTargetBlockAsync<T>(this DbCommand command,
107107
if (target.IsStillAlive())
108108
{
109109
var state = await command.Connection.EnsureOpenAsync(cancellationToken);
110-
if (state == ConnectionState.Closed) behavior = behavior | CommandBehavior.CloseConnection;
110+
if (state == ConnectionState.Closed) behavior |= CommandBehavior.CloseConnection;
111111
using (var reader = await command.ExecuteReaderAsync(behavior, cancellationToken))
112112
{
113113
if (target.IsStillAlive())

Extensions.Retrieve.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static QueryResult<Queue<object[]>> Retrieve(this IDataReader reader, IEn
5959
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
6060
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
6161
public static QueryResult<Queue<object[]>> Retrieve(this IDataReader reader, int n, params int[] others)
62-
=> Retrieve(reader, new[] { n }.Concat(others));
62+
=> Retrieve(reader, Enumerable.Repeat(n, 1).Concat(others));
6363

6464
/// <summary>
6565
/// Iterates all records within the current result set using an IDataReader and returns the desired results.
@@ -84,7 +84,7 @@ public static QueryResult<Queue<object[]>> Retrieve(this IDataReader reader, IEn
8484
/// <param name="others">The remaining column names to request from the reader for each record.</param>
8585
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
8686
public static QueryResult<Queue<object[]>> Retrieve(this IDataReader reader, string c, params string[] others)
87-
=> Retrieve(reader, new[] { c }.Concat(others));
87+
=> Retrieve(reader, Enumerable.Repeat(c, 1).Concat(others));
8888

8989
/// <summary>
9090
/// Iterates all records within the first result set using an IDataReader and returns the results.
@@ -115,7 +115,7 @@ public static QueryResult<Queue<object[]>> Retrieve(this IDbCommand command, IEn
115115
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
116116
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
117117
public static QueryResult<Queue<object[]>> Retrieve(this IDbCommand command, int n, params int[] others)
118-
=> ExecuteReader(command, reader => Retrieve(reader, new[] { n }.Concat(others)));
118+
=> ExecuteReader(command, reader => Retrieve(reader, Enumerable.Repeat(n, 1).Concat(others)));
119119

120120
/// <summary>
121121
/// Iterates all records within the first result set using an IDataReader and returns the desired results as a list of Dictionaries containing only the specified column values.
@@ -136,7 +136,7 @@ public static QueryResult<Queue<object[]>> Retrieve(this IDbCommand command, IEn
136136
/// <param name="others">The remaining column names to request from the reader for each record.</param>
137137
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
138138
public static QueryResult<Queue<object[]>> Retrieve(this IDbCommand command, string c, params string[] others)
139-
=> ExecuteReader(command, reader => Retrieve(reader, new[] { c }.Concat(others)));
139+
=> ExecuteReader(command, reader => Retrieve(reader, Enumerable.Repeat(c, 1).Concat(others)));
140140

141141
/// <summary>
142142
/// Asynchronously enumerates all the remaining values of the current result set of a data reader.
@@ -224,7 +224,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader
224224
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
225225
/// <returns>The QueryResult that contains a buffer block of the results and the column mappings.</returns>
226226
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader reader, int n, params int[] others)
227-
=> RetrieveAsync(reader, new[] { n }.Concat(others));
227+
=> RetrieveAsync(reader, Enumerable.Repeat(n, 1).Concat(others));
228228

229229
/// <summary>
230230
/// Asynchronously enumerates all the remaining values of the current result set of a data reader.
@@ -236,7 +236,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader
236236
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
237237
/// <returns>The QueryResult that contains a buffer block of the results and the column mappings.</returns>
238238
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader reader, CancellationToken token, int n, params int[] others)
239-
=> RetrieveAsync(reader, new[] { n }.Concat(others), token);
239+
=> RetrieveAsync(reader, Enumerable.Repeat(n, 1).Concat(others), token);
240240

241241
/// <summary>
242242
/// Asynchronously enumerates all records within the current result set using an IDataReader and returns the desired results.
@@ -268,7 +268,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader
268268
/// <param name="others">The remaining column names to request from the reader for each record.</param>
269269
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
270270
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader reader, string c, params string[] others)
271-
=> RetrieveAsync(reader, new[] { c }.Concat(others));
271+
=> RetrieveAsync(reader, Enumerable.Repeat(c, 1).Concat(others));
272272

273273
/// <summary>
274274
/// Asynchronously enumerates all records within the current result set using an IDataReader and returns the desired results.
@@ -280,7 +280,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader
280280
/// <param name="others">The remaining column names to request from the reader for each record.</param>
281281
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
282282
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbDataReader reader, CancellationToken token, string c, params string[] others)
283-
=> RetrieveAsync(reader, new[] { c }.Concat(others), false, token);
283+
=> RetrieveAsync(reader, Enumerable.Repeat(c, 1).Concat(others), false, token);
284284

285285
/// <summary>
286286
/// Asynchronously enumerates all the remaining values of the current result set of a data reader.
@@ -317,7 +317,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand co
317317
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
318318
/// <returns>The QueryResult that contains a buffer block of the results and the column mappings.</returns>
319319
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand command, int n, params int[] others)
320-
=> RetrieveAsync(command, new[] { n }.Concat(others));
320+
=> RetrieveAsync(command, Enumerable.Repeat(n, 1).Concat(others));
321321

322322
/// <summary>
323323
/// Asynchronously enumerates all the remaining values of the current result set of a data reader.
@@ -329,7 +329,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand co
329329
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
330330
/// <returns>The QueryResult that contains a buffer block of the results and the column mappings.</returns>
331331
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand command, CancellationToken token, int n, params int[] others)
332-
=> RetrieveAsync(command, new[] { n }.Concat(others), token);
332+
=> RetrieveAsync(command, Enumerable.Repeat(n, 1).Concat(others), token);
333333

334334
/// <summary>
335335
/// Asynchronously enumerates all records within the current result set using an IDataReader and returns the desired results.
@@ -353,7 +353,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand co
353353
/// <param name="others">The remaining column names to request from the reader for each record.</param>
354354
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
355355
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand command, string c, params string[] others)
356-
=> RetrieveAsync(command, new[] { c }.Concat(others));
356+
=> RetrieveAsync(command, Enumerable.Repeat(c, 1).Concat(others));
357357

358358
/// <summary>
359359
/// Asynchronously enumerates all records within the current result set using an IDataReader and returns the desired results.
@@ -365,7 +365,7 @@ public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand co
365365
/// <param name="others">The remaining column names to request from the reader for each record.</param>
366366
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
367367
public static Task<QueryResult<Queue<object[]>>> RetrieveAsync(this DbCommand command, CancellationToken token, string c, params string[] others)
368-
=> RetrieveAsync(command, new[] { c }.Concat(others), false, token);
368+
=> RetrieveAsync(command, Enumerable.Repeat(c, 1).Concat(others), false, token);
369369

370370
}
371371
}

SqlClient/ExpressiveSqlCommand.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ protected override void AddParams(SqlCommand command)
4747
{
4848
foreach (var p in Params)
4949
{
50-
var np = command.Parameters.AddWithValue(p.Name, p.Value);
51-
if (p.Type.HasValue) np.SqlDbType = p.Type.Value;
50+
var np = command
51+
.Parameters
52+
.AddWithValue(p.Name, p.Value);
53+
54+
if (p.Type.HasValue)
55+
np.SqlDbType = p.Type.Value;
5256
}
5357
}
5458

SqlClient/Extensions.CreateCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public static SqlCommand CreateStoredProcedureCommand(this SqlConnection connect
6060
public static SqlCommand CreateCommand(this SqlTransaction transaction,
6161
CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS)
6262
{
63-
var command = transaction.Connection.CreateCommand(type, commandText, secondsTimeout);
63+
var command = transaction
64+
.Connection
65+
.CreateCommand(type, commandText, secondsTimeout);
66+
6467
command.Transaction = transaction;
6568
return command;
6669
}

0 commit comments

Comments
 (0)