Skip to content

Commit 961f37f

Browse files
committed
Made TupleDescriptor's fieldTypes readonly field
1 parent eff8897 commit 961f37f

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

Orm/Xtensive.Orm/Tuples/TupleDescriptor.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,30 @@ namespace Xtensive.Tuples
3232

3333
[NonSerialized]
3434
internal readonly PackedFieldDescriptor[] FieldDescriptors;
35-
36-
[field: NonSerialized]
37-
private Type[] FieldTypes { get; }
35+
36+
[NonSerialized]
37+
private readonly Type[] fieldTypes;
3838

3939
#region IReadOnlyList members
4040

4141
/// <inheritdoc/>
4242
public Type this[int fieldIndex]
4343
{
44-
get => FieldTypes[fieldIndex];
45-
set => throw Exceptions.CollectionIsReadOnly(null);
44+
get => fieldTypes[fieldIndex];
4645
}
4746

4847
/// <inheritdoc/>
4948
public int Count
5049
{
5150
[DebuggerStepThrough]
52-
get => FieldTypes.Length;
51+
get => fieldTypes.Length;
5352
}
5453

5554
/// <inheritdoc/>
5655
public IEnumerator<Type> GetEnumerator()
5756
{
5857
for (int index = 0, count = Count; index < count; index++) {
59-
yield return FieldTypes[index];
58+
yield return fieldTypes[index];
6059
}
6160
}
6261

@@ -80,7 +79,7 @@ public TupleDescriptor Head(int fieldCount)
8079
{
8180
ArgumentValidator.EnsureArgumentIsInRange(fieldCount, 1, Count, nameof(fieldCount));
8281
var fieldTypes = new Type[fieldCount];
83-
Array.Copy(FieldTypes, 0, fieldTypes, 0, fieldCount);
82+
Array.Copy(this.fieldTypes, 0, fieldTypes, 0, fieldCount);
8483
return new TupleDescriptor(fieldTypes);
8584
}
8685

@@ -95,7 +94,7 @@ public TupleDescriptor Tail(int tailFieldCount)
9594
{
9695
ArgumentValidator.EnsureArgumentIsInRange(tailFieldCount, 1, Count, nameof(tailFieldCount));
9796
var fieldTypes = new Type[tailFieldCount];
98-
Array.Copy(FieldTypes, Count - tailFieldCount, fieldTypes, 0, tailFieldCount);
97+
Array.Copy(this.fieldTypes, Count - tailFieldCount, fieldTypes, 0, tailFieldCount);
9998
return new TupleDescriptor(fieldTypes);
10099
}
101100

@@ -108,10 +107,10 @@ public TupleDescriptor Tail(int tailFieldCount)
108107
/// </returns>
109108
public TupleDescriptor Segment(in Segment<int> segment)
110109
{
111-
var fields = new Type[segment.Length];
112-
Array.Copy(FieldTypes, segment.Offset, fields, 0, segment.Length);
110+
var fieldTypes = new Type[segment.Length];
111+
Array.Copy(this.fieldTypes, segment.Offset, fieldTypes, 0, segment.Length);
113112

114-
return new TupleDescriptor(fields);
113+
return new TupleDescriptor(fieldTypes);
115114
}
116115

117116
/// <summary>
@@ -122,27 +121,27 @@ public TupleDescriptor Segment(in Segment<int> segment)
122121
public TupleDescriptor ConcatWith(in TupleDescriptor second)
123122
{
124123
var (firstCount, secondCount) = (Count, second.Count);
125-
var types = new Type[firstCount + secondCount];
126-
Array.Copy(FieldTypes, types, firstCount);
127-
Array.Copy(second.FieldTypes, 0, types, firstCount, secondCount);
124+
var fieldTypes = new Type[firstCount + secondCount];
125+
Array.Copy(this.fieldTypes, fieldTypes, firstCount);
126+
Array.Copy(second.fieldTypes, 0, fieldTypes, firstCount, secondCount);
128127

129-
return new TupleDescriptor(types);
128+
return new TupleDescriptor(fieldTypes);
130129
}
131130

132131
#region IEquatable members, GetHashCode
133132

134133
/// <inheritdoc/>
135134
public bool Equals(TupleDescriptor other)
136135
{
137-
if (FieldTypes == null) {
138-
return other.FieldTypes == null;
136+
if (fieldTypes == null) {
137+
return other.fieldTypes == null;
139138
}
140-
if (other.FieldTypes == null || Count != other.Count) {
139+
if (other.fieldTypes == null || Count != other.Count) {
141140
return false;
142141
}
143142

144143
for (int i = 0, count = Count; i < count; i++) {
145-
if (FieldTypes[i] != other.FieldTypes[i]) {
144+
if (fieldTypes[i] != other.fieldTypes[i]) {
146145
return false;
147146
}
148147
}
@@ -158,7 +157,7 @@ public override int GetHashCode()
158157
{
159158
int result = Count;
160159
for (int i = 0, count = Count; i < count; i++)
161-
result = unchecked (FieldTypes[i].GetHashCode() + 29 * result);
160+
result = unchecked (fieldTypes[i].GetHashCode() + 29 * result);
162161
return result;
163162
}
164163

@@ -179,11 +178,11 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
179178
info.AddValue(nameof(ValuesLength), ValuesLength);
180179
info.AddValue(nameof(ObjectsLength), ObjectsLength);
181180

182-
var typeNames = new string[FieldTypes.Length];
181+
var typeNames = new string[fieldTypes.Length];
183182
for (var i = 0; i < typeNames.Length; i++)
184-
typeNames[i] = FieldTypes[i].ToSerializableForm();
183+
typeNames[i] = fieldTypes[i].ToSerializableForm();
185184

186-
info.AddValue(nameof(FieldTypes), typeNames);
185+
info.AddValue(nameof(fieldTypes), typeNames);
187186
info.AddValue(nameof(FieldDescriptors), FieldDescriptors);
188187
}
189188

@@ -194,7 +193,7 @@ public override string ToString()
194193
for (int i = 0, count = Count; i < count; i++) {
195194
if (i > 0)
196195
sb.Append(", ");
197-
sb.Append(FieldTypes[i].GetShortName());
196+
sb.Append(fieldTypes[i].GetShortName());
198197
}
199198
return string.Format(Strings.TupleDescriptorFormat, sb.ToString());
200199
}
@@ -286,7 +285,7 @@ public static TupleDescriptor Create<T1, T2, T3, T4>()
286285
private TupleDescriptor(Type[] fieldTypes)
287286
{
288287
var fieldCount = fieldTypes.Length;
289-
FieldTypes = fieldTypes;
288+
this.fieldTypes = fieldTypes;
290289
FieldDescriptors = new PackedFieldDescriptor[fieldCount];
291290

292291
switch (fieldCount) {
@@ -295,17 +294,17 @@ private TupleDescriptor(Type[] fieldTypes)
295294
ObjectsLength = 0;
296295
return;
297296
case 1:
298-
TupleLayout.ConfigureLen1(ref FieldTypes[0],
297+
TupleLayout.ConfigureLen1(ref this.fieldTypes[0],
299298
ref FieldDescriptors[0],
300299
out ValuesLength, out ObjectsLength);
301300
break;
302301
case 2:
303-
TupleLayout.ConfigureLen2(FieldTypes,
302+
TupleLayout.ConfigureLen2(this.fieldTypes,
304303
ref FieldDescriptors[0], ref FieldDescriptors[1],
305304
out ValuesLength, out ObjectsLength);
306305
break;
307306
default:
308-
TupleLayout.Configure(FieldTypes, FieldDescriptors, out ValuesLength, out ObjectsLength);
307+
TupleLayout.Configure(this.fieldTypes, FieldDescriptors, out ValuesLength, out ObjectsLength);
309308
break;
310309
}
311310
}
@@ -315,14 +314,14 @@ public TupleDescriptor(SerializationInfo info, StreamingContext context)
315314
ValuesLength = info.GetInt32(nameof(ValuesLength));
316315
ObjectsLength = info.GetInt32(nameof(ObjectsLength));
317316

318-
var typeNames = (string[]) info.GetValue(nameof(FieldTypes), typeof(string[]));
317+
var typeNames = (string[]) info.GetValue(nameof(fieldTypes), typeof(string[]));
319318
FieldDescriptors = (PackedFieldDescriptor[])info.GetValue(
320319
nameof(FieldDescriptors), typeof(PackedFieldDescriptor[]));
321320

322-
FieldTypes = new Type[typeNames.Length];
321+
fieldTypes = new Type[typeNames.Length];
323322
for (var i = 0; i < typeNames.Length; i++) {
324-
FieldTypes[i] = typeNames[i].GetTypeFromSerializableForm();
325-
TupleLayout.ConfigureFieldAccessor(ref FieldDescriptors[i], FieldTypes[i]);
323+
fieldTypes[i] = typeNames[i].GetTypeFromSerializableForm();
324+
TupleLayout.ConfigureFieldAccessor(ref FieldDescriptors[i], fieldTypes[i]);
326325
}
327326
}
328327
}

0 commit comments

Comments
 (0)