Skip to content

Commit 5f5c254

Browse files
authored
Use params ReadOnlySpan<> feature (#373)
* Use `params ReadOnlySpan<>` feature * Entity() ctor
1 parent f7688d5 commit 5f5c254

File tree

11 files changed

+29
-37
lines changed

11 files changed

+29
-37
lines changed

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Extractor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,11 +1289,11 @@ protected virtual ISqlCompileUnit BuildExtractSequencesQuery(ExtractionContext c
12891289
foreach (var (segId, seq) in sequenceMap) {
12901290
if (query.Length == 0) {
12911291
_ = query.AppendFormat("SELECT * FROM (\nSELECT {0} as id, * FROM {1}", segId,
1292-
SqlHelper.Quote(SqlHelper.EscapeSetup.WithQuotes, new[] { seq.Schema.DbName, seq.DbName }));
1292+
SqlHelper.Quote(SqlHelper.EscapeSetup.WithQuotes, [seq.Schema.DbName, seq.DbName]));
12931293
}
12941294
else {
12951295
_ = query.AppendFormat("\nUNION ALL\nSELECT {0} as id, * FROM {1}", segId,
1296-
SqlHelper.Quote(SqlHelper.EscapeSetup.WithQuotes, new[] { seq.Schema.DbName, seq.DbName }));
1296+
SqlHelper.Quote(SqlHelper.EscapeSetup.WithQuotes, [seq.Schema.DbName, seq.DbName]));
12971297
}
12981298
}
12991299
_ = query.Append("\n) all_sequences\nORDER BY id");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public ExtractionContext(Catalog catalog, IReadOnlyCollection<string> targetSche
5858

5959
Catalog = catalog;
6060
TargetSchemas = targetSchemas;
61-
QuotedCatalogName = SqlHelper.QuoteIdentifierWithBrackets(new[] { catalog.Name });
61+
QuotedCatalogName = SqlHelper.QuoteIdentifierWithBrackets([catalog.Name]);
6262

6363
SchemaIndex = new Dictionary<int, Schema>();
6464
ReversedSchemaIndex = new Dictionary<Schema, int>();
@@ -985,4 +985,4 @@ public Extractor(SqlDriver driver)
985985
{
986986
}
987987
}
988-
}
988+
}

Orm/Xtensive.Orm/Orm/Entity.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ internal IEnumerable<FieldInfo> GetKeyFieldsOfEntityType()
446446
return TypeInfo.Key.Fields.Where(field => field.IsEntity && !field.IsNested).Select(field => field);
447447
}
448448

449-
internal void RegisterKeyFieldsOfEntityTypeForRemap(Key keyOfThisEntity, params object[] values)
449+
internal void RegisterKeyFieldsOfEntityTypeForRemap(Key keyOfThisEntity, params ReadOnlySpan<object> values)
450450
{
451451
foreach (var fieldInfo in GetKeyFieldsOfEntityType()) {
452452
var referencedEntity = values[fieldInfo.MappingInfo.Offset] as Entity;
@@ -888,10 +888,9 @@ internal Entity(Session session, Tuple keyTuple)
888888
/// }
889889
/// </code>
890890
/// </example>
891-
protected Entity(params object[] values)
891+
protected Entity(params ReadOnlySpan<object> values)
892892
{
893893
try {
894-
ArgumentNullException.ThrowIfNull(values);
895894
var key = Key.Create(Session.Domain, Session.StorageNodeId, GetTypeInfo(), TypeReferenceAccuracy.ExactType, values);
896895
State = Session.CreateEntityState(key, true);
897896
changeVersionOnSetAttempt = ShouldChangeOnSetAttempt();
@@ -939,11 +938,10 @@ protected Entity(params object[] values)
939938
/// }
940939
/// </code>
941940
/// </example>
942-
protected Entity(Session session, params object[] values)
941+
protected Entity(Session session, params ReadOnlySpan<object> values)
943942
: base(session)
944943
{
945944
try {
946-
ArgumentNullException.ThrowIfNull(values);
947945
var key = Key.Create(Session.Domain, Session.StorageNodeId, GetTypeInfo(), TypeReferenceAccuracy.ExactType, values);
948946
State = Session.CreateEntityState(key, true);
949947
changeVersionOnSetAttempt = ShouldChangeOnSetAttempt();

Orm/Xtensive.Orm/Orm/Internals/KeyFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static Key Materialize(Domain domain, string nodeId,
6161
}
6262

6363
public static Key Materialize(Domain domain, string nodeId,
64-
TypeInfo type, TypeReferenceAccuracy accuracy, params object[] values)
64+
TypeInfo type, TypeReferenceAccuracy accuracy, params ReadOnlySpan<object> values)
6565
{
6666
var keyInfo = type.Key;
6767
ArgumentValidator.EnsureArgumentIsInRange(values.Length, 1, keyInfo.TupleDescriptor.Count, "values");

Orm/Xtensive.Orm/Orm/Key.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,8 @@ public static Key Create([NotNull] Domain domain, [NotNull] string nodeId, [NotN
453453
return Create(domain, nodeId, domain.Model.Types[type], accuracy, values);
454454
}
455455

456-
internal static Key Create(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, object[] values)
457-
{
458-
return KeyFactory.Materialize(domain, nodeId, type, accuracy, values);
459-
}
456+
internal static Key Create(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, ReadOnlySpan<object> values) =>
457+
KeyFactory.Materialize(domain, nodeId, type, accuracy, values);
460458

461459
#endregion
462460

Orm/Xtensive.Orm/Orm/Linq/Translator.Materialization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal sealed partial class Translator
2727
private static readonly MethodInfo VisitLocalCollectionSequenceMethod = typeof(Translator).GetMethodEx(nameof(VisitLocalCollectionSequence),
2828
BindingFlags.NonPublic | BindingFlags.Instance,
2929
new[] { "TItem" },
30-
new object[] { WellKnownTypes.Expression });
30+
[WellKnownTypes.Expression]);
3131

3232
private static readonly ParameterExpression ParameterContext = Expression.Parameter(WellKnownOrmTypes.ParameterContext, "parameterContext");
3333
private static readonly ParameterExpression TupleReader = Expression.Parameter(typeof(RecordSetReader), "tupleReader");

Orm/Xtensive.Orm/Orm/QueryEndpoint.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,10 @@ public async ValueTask<T> SingleAsync<T>(Key key, CancellationToken ct = default
461461
/// <see langword="null"/>, if there is no such entity.
462462
/// </returns>
463463
public async ValueTask<T> SingleAsync<T>(object key, CancellationToken ct = default) where T : class, IEntity =>
464-
(T)(object)(await SingleAsync(GetKeyByValues<T>(new[] { key }), ct));
464+
(T)(object)(await SingleAsync(GetKeyByValues<T>([key]), ct));
465465

466466
public async ValueTask<T> SingleAsync<T>(object key1, object key2, CancellationToken ct = default) where T : class, IEntity =>
467-
(T)(object)(await SingleAsync(GetKeyByValues<T>(new[] { key1, key2 }), ct));
467+
(T)(object)(await SingleAsync(GetKeyByValues<T>([key1, key2]), ct));
468468

469469
/// <summary>
470470
/// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
@@ -488,10 +488,10 @@ public async ValueTask<T> SingleOrDefaultAsync<T>(Key key, CancellationToken ct
488488
/// The <see cref="Entity"/> specified <paramref name="keyValues"/> identify.
489489
/// </returns>
490490
public async ValueTask<T> SingleOrDefaultAsync<T>(object key, CancellationToken ct = default) where T : class, IEntity =>
491-
(T)(object)(await SingleOrDefaultAsync(GetKeyByValues<T>(new[] { key }), ct));
491+
(T)(object)(await SingleOrDefaultAsync(GetKeyByValues<T>([key]), ct));
492492

493493
public async ValueTask<T> SingleOrDefaultAsync<T>(object key1, object key2, CancellationToken ct = default) where T : class, IEntity =>
494-
(T)(object)(await SingleOrDefaultAsync(GetKeyByValues<T>(new[] { key1, key2 }), ct));
494+
(T)(object)(await SingleOrDefaultAsync(GetKeyByValues<T>([key1, key2]), ct));
495495

496496
/// <summary>
497497
/// Fetches multiple instances of specified type by provided <paramref name="keys"/>.

Orm/Xtensive.Orm/Reflection/MethodHelper.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public struct AnyArrayPlaceholder
4242
/// otherwise, <see langword="null"/>.</returns>
4343
[DebuggerStepThrough]
4444
[CanBeNull]
45-
public static MethodInfo GetMethodEx(this Type type, string name, BindingFlags bindingFlags, string[] genericArgumentNames, object[] parameterTypes)
45+
public static MethodInfo GetMethodEx(this Type type, string name, BindingFlags bindingFlags, string[] genericArgumentNames, ReadOnlySpan<object> parameterTypes)
4646
{
4747
ArgumentNullException.ThrowIfNull(type);
4848
ArgumentException.ThrowIfNullOrEmpty(name);
@@ -51,10 +51,6 @@ public static MethodInfo GetMethodEx(this Type type, string name, BindingFlags b
5151
genericArgumentNames = Array.Empty<string>();
5252
}
5353

54-
if (parameterTypes == null) {
55-
parameterTypes = Array.Empty<object>();
56-
}
57-
5854
var parameterTypesAreFullyDefined = true;
5955
for (var i = 0; i < parameterTypes.Length; i++) {
6056
var parameterType = parameterTypes[i] as Type;
@@ -331,7 +327,7 @@ private static EventInfo GetEventRecursive(BindingFlags bindingFlags, string eve
331327

332328
#region Private \ internal methods
333329

334-
private static bool CheckMethod(MethodBase m, string name, string[] genericArgumentNames, object[] parameterTypes)
330+
private static bool CheckMethod(MethodBase m, string name, string[] genericArgumentNames, ReadOnlySpan<object> parameterTypes)
335331
{
336332
// Checking name
337333
if (!m.Name.Equals(name, StringComparison.Ordinal)) {

Orm/Xtensive.Orm/Sql/Compiler/Internals/PostCompiler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ private void Visit(SchemaNodePlaceholderNode node)
6161

6262
var schema = node.SchemaNode.Schema;
6363

64-
var names = (node.DbQualified)
65-
? new string[] { schema.Catalog.GetActualDbName(configuration.DatabaseMapping), schema.GetActualDbName(configuration.SchemaMapping), node.SchemaNode.DbName }
66-
: new string[] { schema.GetActualDbName(configuration.SchemaMapping), node.SchemaNode.DbName };
64+
var quotedNames = (node.DbQualified)
65+
? SqlHelper.Quote(node.EscapeSetup, [schema.Catalog.GetActualDbName(configuration.DatabaseMapping), schema.GetActualDbName(configuration.SchemaMapping), node.SchemaNode.DbName])
66+
: SqlHelper.Quote(node.EscapeSetup, [schema.GetActualDbName(configuration.SchemaMapping), node.SchemaNode.DbName]);
6767

68-
_ = result.Append(SqlHelper.Quote(node.EscapeSetup, names));
68+
_ = result.Append(quotedNames);
6969
}
7070

7171
public override void Visit(CycleItemNode node)

Orm/Xtensive.Orm/Sql/Compiler/SqlTranslator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ protected virtual void TranslateStringChar(IOutput output, char ch)
23962396
/// <param name="output">The output.</param>
23972397
/// <param name="name">The identifier.</param>
23982398
/// <param name="moreNames">Additional names (optional).</param>
2399-
public void TranslateIdentifier(IOutput output, string name, params string[] moreNames)
2399+
public void TranslateIdentifier(IOutput output, string name, params ReadOnlySpan<string> moreNames)
24002400
{
24012401
if (string.IsNullOrEmpty(name))
24022402
return;
@@ -2414,7 +2414,7 @@ public void TranslateIdentifier(IOutput output, string name, params string[] mor
24142414
}
24152415
_ = output.AppendLiteral(setup.Closer);
24162416

2417-
if (moreNames?.Length == 0)
2417+
if (moreNames.Length == 0)
24182418
return;
24192419

24202420
foreach (var aName in moreNames) {
@@ -2514,7 +2514,7 @@ public virtual string QuoteString(string str)
25142514
/// <remarks>
25152515
/// Use TranslateIdentifier instead of this method within SqlTranslators/SqlCompilers where possible.
25162516
/// </remarks>
2517-
public string QuoteIdentifier(params string[] names) =>
2517+
public string QuoteIdentifier(params ReadOnlySpan<string> names) =>
25182518
//Use TranslateIdentifier instead of this method within SqlTranslators/SqlCompilers where possible
25192519
SqlHelper.Quote(EscapeSetup, names);
25202520

@@ -2643,4 +2643,4 @@ protected SqlTranslator(SqlDriver driver)
26432643
supportsMultischemaQueries = queryFeatures.Supports(QueryFeatures.MultischemaQueries);
26442644
}
26452645
}
2646-
}
2646+
}

Orm/Xtensive.Orm/Sql/SqlHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,26 @@ public static void ValidateConnectionUrl(UrlInfo url)
6969
/// </summary>
7070
/// <returns>Quoted identifier.</returns>
7171
[MethodImpl(MethodImplOptions.AggressiveInlining)]
72-
public static string QuoteIdentifierWithQuotes(string[] names)
72+
public static string QuoteIdentifierWithQuotes(ReadOnlySpan<string> names)
7373
=> Quote(EscapeSetup.WithQuotes, names);
7474

7575
/// <summary>
7676
/// Quotes the specified identifier with square brackets (i.e. []).
7777
/// </summary>
7878
/// <returns>Quoted indentifier.</returns>
7979
[MethodImpl(MethodImplOptions.AggressiveInlining)]
80-
public static string QuoteIdentifierWithBrackets(string[] names)
80+
public static string QuoteIdentifierWithBrackets(ReadOnlySpan<string> names)
8181
=> Quote(EscapeSetup.WithBrackets, names);
8282

8383
/// <summary>
8484
/// Quotes the specified identifier with square brackets (i.e. ``).
8585
/// </summary>
8686
/// <returns>Quoted identifier.</returns>
8787
[MethodImpl(MethodImplOptions.AggressiveInlining)]
88-
public static string QuoteIdentifierWithBackTick(string[] names)
88+
public static string QuoteIdentifierWithBackTick(ReadOnlySpan<string> names)
8989
=> Quote(EscapeSetup.WithBackTick, names);
9090

91-
public static unsafe string Quote(in EscapeSetup setup, string[] names)
91+
public static unsafe string Quote(in EscapeSetup setup, ReadOnlySpan<string> names)
9292
{
9393
// That's one of frequently called methods, so it's optimized for speed.
9494

0 commit comments

Comments
 (0)