diff --git a/Orm/Xtensive.Orm/Orm/Internals/GenericKeyFactory.cs b/Orm/Xtensive.Orm/Orm/Internals/GenericKeyFactory.cs index dcdd9fde21..0f4fccbe22 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/GenericKeyFactory.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/GenericKeyFactory.cs @@ -1,10 +1,11 @@ -// Copyright (C) 2003-2010 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2003-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Alexander Nikolaev // Created: 2009.07.27 using System; +using System.Collections.Generic; using Xtensive.Orm.Model; using Tuple = Xtensive.Tuples.Tuple; @@ -15,14 +16,14 @@ internal sealed class GenericKeyFactory { public readonly Type Type; public readonly Func DefaultConstructor; - public readonly Func KeyIndexBasedConstructor; + public readonly Func, Key> KeyIndexBasedConstructor; // Constructors public GenericKeyFactory(Type type, Func defaultConstructor, - Func keyIndexBasedConstructor) + Func, Key> keyIndexBasedConstructor) { Type = type; DefaultConstructor = defaultConstructor; diff --git a/Orm/Xtensive.Orm/Orm/Internals/KeyFactory.cs b/Orm/Xtensive.Orm/Orm/Internals/KeyFactory.cs index a683143167..32a8eda870 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/KeyFactory.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/KeyFactory.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2020 Xtensive LLC. +// Copyright (C) 2009-2021 Xtensive LLC. // This code is distributed under MIT license terms. // See the License.txt file in the project root for more information. // Created by: Dmitri Maximov @@ -35,7 +35,7 @@ public static Key Generate(Session session, TypeInfo typeInfo) } public static Key Materialize(Domain domain, string nodeId, - TypeInfo type, Tuple value, TypeReferenceAccuracy accuracy, bool canCache, int[] keyIndexes) + TypeInfo type, Tuple value, TypeReferenceAccuracy accuracy, bool canCache, IReadOnlyList keyIndexes) { var hierarchy = type.Hierarchy; var keyInfo = type.Key; @@ -131,18 +131,18 @@ public static bool IsValidKeyTuple(Tuple tuple) return true; } - public static bool IsValidKeyTuple(Tuple tuple, int[] keyIndexes) + public static bool IsValidKeyTuple(Tuple tuple, IReadOnlyList keyIndexes) { if (keyIndexes==null) return IsValidKeyTuple(tuple); - var limit = keyIndexes.Length; + var limit = keyIndexes.Count; for (int i = 0; i < limit; i++) if (tuple.GetFieldState(keyIndexes[i]).IsNull()) return false; return true; } - private static Key CreateGenericKey(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, Tuple tuple, int[] keyIndexes) + private static Key CreateGenericKey(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, Tuple tuple, IReadOnlyList keyIndexes) { var keyTypeInfo = domain.GenericKeyFactories.GetOrAdd(type, BuildGenericKeyFactory); if (keyIndexes==null) @@ -158,7 +158,7 @@ private static GenericKeyFactory BuildGenericKeyFactory(TypeInfo typeInfo) keyType = keyType.MakeGenericType(descriptor.ToArray(descriptor.Count)); var defaultConstructor = DelegateHelper.CreateDelegate>( null, keyType, "Create", Array.Empty()); - var keyIndexBasedConstructor = DelegateHelper.CreateDelegate>( + var keyIndexBasedConstructor = DelegateHelper.CreateDelegate, Key>>( null, keyType, "Create", Array.Empty()); return new GenericKeyFactory(keyType, defaultConstructor, keyIndexBasedConstructor); } diff --git a/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3,T4}.cs b/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3,T4}.cs index bc95152f1a..4825bed798 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3,T4}.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3,T4}.cs @@ -1,10 +1,11 @@ -// Copyright (C) 2003-2010 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2003-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Alexander Nikolaev // Created: 2009.07.13 using System; +using System.Collections.Generic; using JetBrains.Annotations; using Xtensive.Core; using Xtensive.Orm.Model; @@ -16,13 +17,13 @@ namespace Xtensive.Orm.Internals [Serializable] internal sealed class Key : Key { - private static readonly Predicate equalityComparer1 = + private static readonly Predicate EqualityComparer1 = ComparerProvider.Default.GetComparer().Equals; - private static readonly Predicate equalityComparer2 = + private static readonly Predicate EqualityComparer2 = ComparerProvider.Default.GetComparer().Equals; - private static readonly Predicate equalityComparer3 = + private static readonly Predicate EqualityComparer3 = ComparerProvider.Default.GetComparer().Equals; - private static readonly Predicate equalityComparer4 = + private static readonly Predicate EqualityComparer4 = ComparerProvider.Default.GetComparer().Equals; private readonly T1 value1; @@ -46,10 +47,10 @@ protected override bool ValueEquals(Key other) if (otherKey == null) return false; return - equalityComparer4.Invoke(value4, otherKey.value4) && - equalityComparer3.Invoke(value3, otherKey.value3) && - equalityComparer2.Invoke(value2, otherKey.value2) && - equalityComparer1.Invoke(value1, otherKey.value1); + EqualityComparer4.Invoke(value4, otherKey.value4) && + EqualityComparer3.Invoke(value3, otherKey.value3) && + EqualityComparer2.Invoke(value2, otherKey.value2) && + EqualityComparer1.Invoke(value1, otherKey.value1); } protected override int CalculateHashCode() @@ -62,7 +63,7 @@ protected override int CalculateHashCode() } [UsedImplicitly] - public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, int[] keyIndexes) + public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, IReadOnlyList keyIndexes) { return new Key(nodeId, type, accuracy, tuple.GetValueOrDefault(keyIndexes[0]), @@ -81,7 +82,7 @@ public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenc tuple.GetValueOrDefault(3)); } - + // Constructors private Key(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, T1 value1, T2 value2, T3 value3, T4 value4) diff --git a/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3}.cs b/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3}.cs index 9296c0ec9f..f1c9fa0a8e 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3}.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2,T3}.cs @@ -1,10 +1,11 @@ -// Copyright (C) 2003-2010 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2003-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Alexander Nikolaev // Created: 2009.07.13 using System; +using System.Collections.Generic; using JetBrains.Annotations; using Xtensive.Core; using Xtensive.Orm.Model; @@ -16,11 +17,11 @@ namespace Xtensive.Orm.Internals [Serializable] internal sealed class Key : Key { - private static readonly Predicate equalityComparer1 = + private static readonly Predicate EqualityComparer1 = ComparerProvider.Default.GetComparer().Equals; - private static readonly Predicate equalityComparer2 = + private static readonly Predicate EqualityComparer2 = ComparerProvider.Default.GetComparer().Equals; - private static readonly Predicate equalityComparer3 = + private static readonly Predicate EqualityComparer3 = ComparerProvider.Default.GetComparer().Equals; private readonly T1 value1; @@ -42,9 +43,9 @@ protected override bool ValueEquals(Key other) if (otherKey == null) return false; return - equalityComparer3.Invoke(value3, otherKey.value3) && - equalityComparer2.Invoke(value2, otherKey.value2) && - equalityComparer1.Invoke(value1, otherKey.value1); + EqualityComparer3.Invoke(value3, otherKey.value3) && + EqualityComparer2.Invoke(value2, otherKey.value2) && + EqualityComparer1.Invoke(value1, otherKey.value1); } protected override int CalculateHashCode() @@ -56,7 +57,7 @@ protected override int CalculateHashCode() } [UsedImplicitly] - public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, int[] keyIndexes) + public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, IReadOnlyList keyIndexes) { return new Key(nodeId, type, accuracy, tuple.GetValueOrDefault(keyIndexes[0]), @@ -73,7 +74,7 @@ public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenc tuple.GetValueOrDefault(2)); } - + // Constructors private Key(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, T1 value1, T2 value2, T3 value3) diff --git a/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2}.cs b/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2}.cs index cdf214aa05..9f4834c3e5 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2}.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Key{T1,T2}.cs @@ -1,10 +1,11 @@ -// Copyright (C) 2003-2010 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2003-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Alexander Nikolaev // Created: 2009.07.13 using System; +using System.Collections.Generic; using JetBrains.Annotations; using Xtensive.Core; using Xtensive.Orm.Model; @@ -16,9 +17,9 @@ namespace Xtensive.Orm.Internals [Serializable] internal sealed class Key : Key { - private static readonly Predicate equalityComparer1 = + private static readonly Predicate EqualityComparer1 = ComparerProvider.Default.GetComparer().Equals; - private static readonly Predicate equalityComparer2 = + private static readonly Predicate EqualityComparer2 = ComparerProvider.Default.GetComparer().Equals; private readonly T1 value1; @@ -38,8 +39,8 @@ protected override bool ValueEquals(Key other) if (otherKey == null) return false; return - equalityComparer2.Invoke(value2, otherKey.value2) && - equalityComparer1.Invoke(value1, otherKey.value1); + EqualityComparer2.Invoke(value2, otherKey.value2) && + EqualityComparer1.Invoke(value1, otherKey.value1); } protected override int CalculateHashCode() @@ -48,7 +49,7 @@ protected override int CalculateHashCode() } [UsedImplicitly] - public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, int[] keyIndexes) + public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, IReadOnlyList keyIndexes) { return new Key(nodeId, type, accuracy, tuple.GetValueOrDefault(keyIndexes[0]), @@ -63,7 +64,7 @@ public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenc tuple.GetValueOrDefault(1)); } - + // Constructors private Key(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, T1 value1, T2 value2) diff --git a/Orm/Xtensive.Orm/Orm/Internals/Key{T}.cs b/Orm/Xtensive.Orm/Orm/Internals/Key{T}.cs index 80f35684e8..332f886dcf 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Key{T}.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Key{T}.cs @@ -1,10 +1,11 @@ -// Copyright (C) 2003-2010 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2003-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Alexander Nikolaev // Created: 2009.07.13 using System; +using System.Collections.Generic; using JetBrains.Annotations; using Xtensive.Core; using Xtensive.Orm.Model; @@ -16,7 +17,7 @@ namespace Xtensive.Orm.Internals [Serializable] internal sealed class Key : Key { - private static readonly Predicate equalityComparer1 = + private static readonly Predicate EqualityComparer1 = ComparerProvider.Default.GetComparer().Equals; private readonly T value1; @@ -34,7 +35,7 @@ protected override bool ValueEquals(Key other) if (otherKey == null) return false; return - equalityComparer1.Invoke(value1, otherKey.value1); + EqualityComparer1.Invoke(value1, otherKey.value1); } protected override int CalculateHashCode() @@ -43,7 +44,7 @@ protected override int CalculateHashCode() } [UsedImplicitly] - public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, int[] keyIndexes) + public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, IReadOnlyList keyIndexes) { return new Key(nodeId, type, accuracy, tuple.GetValueOrDefault(keyIndexes[0])); } @@ -54,7 +55,7 @@ public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenc return new Key(nodeId, type, accuracy, tuple.GetValueOrDefault(0)); } - + // Constructors private Key(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, T value) diff --git a/Orm/Xtensive.Orm/Orm/Internals/TypeMapping.cs b/Orm/Xtensive.Orm/Orm/Internals/TypeMapping.cs index 92351f27ce..9848fbaec1 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/TypeMapping.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/TypeMapping.cs @@ -1,9 +1,10 @@ -// Copyright (C) 2003-2010 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2003-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Dmitri Maximov // Created: 2008.08.08 +using System.Collections.Generic; using Xtensive.Tuples.Transform; using Xtensive.Orm.Model; @@ -13,13 +14,13 @@ internal readonly struct TypeMapping { public readonly TypeInfo Type; public readonly MapTransform KeyTransform; - public readonly int[] KeyIndexes; + public readonly IReadOnlyList KeyIndexes; public readonly MapTransform Transform; // Constructors - public TypeMapping(TypeInfo type, MapTransform keyTransform, MapTransform transform, int[] keyIndexes) + public TypeMapping(TypeInfo type, MapTransform keyTransform, MapTransform transform, IReadOnlyList keyIndexes) { Type = type; KeyTransform = keyTransform; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Materialization/ItemMaterializationContext.cs b/Orm/Xtensive.Orm/Orm/Linq/Materialization/ItemMaterializationContext.cs index ab92be3338..8de179ee01 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Materialization/ItemMaterializationContext.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Materialization/ItemMaterializationContext.cs @@ -47,7 +47,7 @@ public Entity Materialize(int entityIndex, int typeIdIndex, TypeInfo type, Pair< var keyIndexes = materializationInfo.KeyIndexes; if (!KeyFactory.IsValidKeyTuple(tuple, keyIndexes)) return null; - if (keyIndexes.Length <= WellKnown.MaxGenericKeyLength) + if (keyIndexes.Count <= WellKnown.MaxGenericKeyLength) key = KeyFactory.Materialize(Session.Domain, Session.StorageNodeId, materializationInfo.Type, tuple, accuracy, canCache, keyIndexes); else { var keyTuple = materializationInfo.KeyTransform.Apply(TupleTransformType.TransformedTuple, tuple); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationContext.cs b/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationContext.cs index 09a482ae83..0909a1c341 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationContext.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationContext.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2020 Xtensive LLC. +// Copyright (C) 2009-2021 Xtensive LLC. // This code is distributed under MIT license terms. // See the License.txt file in the project root for more information. // Created by: Alexis Kochetov @@ -90,8 +90,8 @@ public TypeMapping GetTypeMapping(int entityIndex, TypeInfo approximateType, int typeColumnMap = newColumns; } - int[] allIndexes = MaterializationHelper.CreateSingleSourceMap(descriptor.Count, typeColumnMap); - int[] keyIndexes = allIndexes.Take(keyInfo.TupleDescriptor.Count).ToArray(); + ArraySegment allIndexes = MaterializationHelper.CreateSingleSourceMap(descriptor.Count, typeColumnMap); + ArraySegment keyIndexes = allIndexes.Slice(0, keyInfo.TupleDescriptor.Count); var transform = new MapTransform(true, descriptor, allIndexes); var keyTransform = new MapTransform(true, keyInfo.TupleDescriptor, keyIndexes); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationHelper.cs b/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationHelper.cs index 15e8bbc03c..025523cf85 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationHelper.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationHelper.cs @@ -46,9 +46,7 @@ internal static class MaterializationHelper public static int[] CreateSingleSourceMap(int targetLength, IReadOnlyList> remappedColumns) { var map = new int[targetLength]; - for (var i = 0; i < map.Length; i++) { - map[i] = MapTransform.NoMapping; - } + Array.Fill(map, MapTransform.NoMapping); for (var i = 0; i < remappedColumns.Count; i++) { var remappedColumn = remappedColumns[i];