Skip to content

Commit cf82f3c

Browse files
committed
No struct checks for default for internal usage
- everywhere inside the project transformations are perforemed on valid descriptors so we can skip checks of structs, transformations are public though so we have to keep validation in public ctor
1 parent 961f37f commit cf82f3c

9 files changed

Lines changed: 59 additions & 13 deletions

File tree

Orm/Xtensive.Orm/Orm/EntitySetBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,6 @@ protected EntitySetBase(Entity owner, FieldInfo field)
10551055
var domain = Session.Domain;
10561056
var itemType = domain.Model.Types[Field.ItemType];
10571057
auxilaryTypeKeyTransform = new ConcatTransform(
1058-
false,
10591058
owner.TypeInfo.Key.TupleDescriptor,
10601059
itemType.Key.TupleDescriptor);
10611060
}

Orm/Xtensive.Orm/Orm/Internals/KeyRemapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2014-2020 Xtensive LLC.
1+
// Copyright (C) 2014-2020 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
@@ -53,7 +53,7 @@ private void RemapEntitySetReference(RemapContext context, ReferenceFieldChangeI
5353
var fieldOwnerKey = context.TryRemapKey(info.FieldOwner);
5454
var fieldValueKey = context.TryRemapKey(info.FieldValue);
5555

56-
var transformer = new ConcatTransform(false, fieldOwnerKey.Value.Descriptor, fieldValueKey.Value.Descriptor);
56+
var transformer = new ConcatTransform(fieldOwnerKey.Value.Descriptor, fieldValueKey.Value.Descriptor);
5757
var combinedTuple = transformer.Apply(TupleTransformType.Tuple, fieldOwnerKey.Value, fieldValueKey.Value);
5858

5959
var newCombinedKey = Key.Create(Session.Domain, Session.StorageNodeId, fieldAssociation.AuxiliaryType, TypeReferenceAccuracy.ExactType, combinedTuple);

Orm/Xtensive.Orm/Orm/Linq/Materialization/MaterializationContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public TypeMapping GetTypeMapping(int entityIndex, TypeInfo approximateType, int
9292
ArraySegment<int> allIndexes = MaterializationHelper.CreateSingleSourceMap(descriptor.Count, typeColumnMap);
9393
ArraySegment<int> keyIndexes = allIndexes.Slice(0, keyInfo.TupleDescriptor.Count);
9494

95-
var transform = new MapTransform(true, descriptor, allIndexes);
96-
var keyTransform = new MapTransform(true, keyInfo.TupleDescriptor, keyIndexes);
95+
var transform = new MapTransform(descriptor, allIndexes);
96+
var keyTransform = new MapTransform(keyInfo.TupleDescriptor, keyIndexes);
9797

9898
result = new TypeMapping(type, keyTransform, transform, keyIndexes);
9999

Orm/Xtensive.Orm/Orm/Model/FieldInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ private void CreateMappingInfo()
699699

700700
if (IsEntity || IsStructure) {
701701
valueExtractor = new SegmentTransform(
702-
false, reflectedType.TupleDescriptor, new Segment<int>(mappingInfo.Offset, mappingInfo.Length));
702+
reflectedType.TupleDescriptor, new Segment<int>(mappingInfo.Offset, mappingInfo.Length));
703703
}
704704
}
705705

Orm/Xtensive.Orm/Orm/Rse/Transformation/RedundantColumnRemover.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected override RawProvider VisitRaw(RawProvider provider)
4646
var mapping = mappings[provider];
4747
if (mapping.SequenceEqual(Enumerable.Range(0, provider.Header.Length)))
4848
return provider;
49-
var mappingTransform = new MapTransform(true, provider.Header.TupleDescriptor, mapping);
49+
var mappingTransform = new MapTransform(provider.Header.TupleDescriptor, mapping);
5050
var newExpression = RemapRawProviderSource(provider.Source, mappingTransform);
5151
return new RawProvider(provider.Header.Select(mapping), newExpression);
5252
}

Orm/Xtensive.Orm/Tuples/Transform/ConcatTransform.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,29 @@ public override string ToString()
8787
/// <param name="second">The <see cref="TupleDescriptor"/> of the second source <see cref="Tuple"/>.</param>
8888
public ConcatTransform(bool isReadOnly, TupleDescriptor first, TupleDescriptor second)
8989
{
90-
ArgumentValidator.EnsureArgumentIsNotDefault(first, nameof(first));
91-
ArgumentValidator.EnsureArgumentIsNotDefault(second, nameof(second));
90+
if (first == default)
91+
throw new ArgumentException("Argument is default instance.", nameof(first));
92+
93+
if (second == default)
94+
throw new ArgumentException("Argument is default instance.", nameof(second));
9295

9396
IsReadOnly = isReadOnly;
9497
Descriptor = first.ConcatWith(second);
9598
this.sourceParts = (first.Count, second.Count);
9699
}
100+
101+
102+
/// <summary>
103+
/// Initializes a new instance of this type.
104+
/// </summary>
105+
/// <param name="first">The <see cref="TupleDescriptor"/> of the first source <see cref="Tuple"/>.</param>
106+
/// <param name="second">The <see cref="TupleDescriptor"/> of the second source <see cref="Tuple"/>.</param>
107+
// WARNING !!!!! NO CHECKS FOR DEFAULT VALUES FOR THE SAKE OF PEFRORMANCE
108+
internal ConcatTransform(TupleDescriptor first, TupleDescriptor second)
109+
{
110+
IsReadOnly = false;
111+
Descriptor = first.ConcatWith(second);
112+
this.sourceParts = (first.Count, second.Count);
113+
}
97114
}
98115
}

Orm/Xtensive.Orm/Tuples/Transform/MapTransform.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,29 @@ public override string ToString()
8181
/// <param name="map"><see cref="Map"/> property value.</param>
8282
public MapTransform(bool isReadOnly, TupleDescriptor descriptor, IReadOnlyList<int> map)
8383
{
84-
ArgumentValidator.EnsureArgumentIsNotDefault(descriptor, nameof(descriptor));
84+
if (descriptor == default)
85+
throw new ArgumentException("Argument is default instance.",nameof(descriptor));
8586

8687
IsReadOnly = isReadOnly;
8788
Descriptor = descriptor;
8889

8990
this.map = map ?? throw new ArgumentNullException(nameof(map));
9091
}
92+
93+
94+
95+
/// <summary>
96+
/// Initializes a new instance of this type with <see cref="IsReadOnly"/> = <see langword="true"/>.
97+
/// </summary>
98+
/// <param name="descriptor">The <see cref="TupleDescriptor"/> of the target <see cref="Tuple"/>.</param>
99+
/// <param name="map"><see cref="Map"/> property value.</param>
100+
// BE CAREFUL, NO VALIDATION OF PARAMETERS for the sake of performance
101+
internal MapTransform(TupleDescriptor descriptor, IReadOnlyList<int> map)
102+
{
103+
IsReadOnly = true;
104+
Descriptor = descriptor;
105+
106+
this.map = map ?? throw new ArgumentNullException(nameof(map));
107+
}
91108
}
92109
}

Orm/Xtensive.Orm/Tuples/Transform/SegmentTransform.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,23 @@ public override string ToString()
7575
/// <param name="segment">The segment to extract.</param>
7676
public SegmentTransform(bool isReadOnly, TupleDescriptor sourceDescriptor, in Segment<int> segment)
7777
{
78-
ArgumentValidator.EnsureArgumentIsNotDefault(sourceDescriptor, nameof(sourceDescriptor));
78+
if (sourceDescriptor == default)
79+
throw new ArgumentException("Argument is default instance.", nameof(sourceDescriptor));
7980

8081
IsReadOnly = isReadOnly;
82+
Descriptor = sourceDescriptor.Segment(segment);
83+
this.segment = segment;
84+
}
8185

86+
/// <summary>
87+
/// Initializes a new instance of this type.
88+
/// </summary>
89+
/// <param name="sourceDescriptor">The <see cref="TupleDescriptor"/> of the source <see cref="Tuple"/>.</param>
90+
/// <param name="segment">The segment to extract.</param>
91+
// WARNING !!!!! NO CHECKS FOR DEFAULT VALUES FOR THE SAKE OF PEFRORMANCE
92+
internal SegmentTransform(TupleDescriptor sourceDescriptor, in Segment<int> segment)
93+
{
94+
IsReadOnly = false;
8295
Descriptor = sourceDescriptor.Segment(segment);
8396
this.segment = segment;
8497
}

Orm/Xtensive.Orm/Tuples/TupleExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static void CopyTo(this Tuple source, Tuple target, IReadOnlyList<int> ma
115115
/// <returns></returns>
116116
public static Tuple Concat(this Tuple left, Tuple right)
117117
{
118-
var transform = new ConcatTransform(false, left.Descriptor, right.Descriptor);
118+
var transform = new ConcatTransform(left.Descriptor, right.Descriptor);
119119
return transform.Apply(TupleTransformType.TransformedTuple, left, right);
120120
}
121121

@@ -127,7 +127,7 @@ public static Tuple Concat(this Tuple left, Tuple right)
127127
/// <returns></returns>
128128
public static Tuple GetSegment(this Tuple tuple, in Segment<int> segment)
129129
{
130-
var transform = new SegmentTransform(false, tuple.Descriptor, segment);
130+
var transform = new SegmentTransform(tuple.Descriptor, segment);
131131
return transform.Apply(TupleTransformType.TransformedTuple, tuple);
132132
}
133133

0 commit comments

Comments
 (0)