Skip to content

Commit 17e2d79

Browse files
committed
Get rid of unused class Deque<> (#339)
* Get rid of unused `Dequeue<>` * Make `OperationRegistry` internal
1 parent 7c2c48b commit 17e2d79

File tree

13 files changed

+61
-962
lines changed

13 files changed

+61
-962
lines changed

Orm/Xtensive.Orm/Collections/Deque.cs

-663
This file was deleted.

Orm/Xtensive.Orm/Collections/Interfaces/IDeque.cs

-153
This file was deleted.

Orm/Xtensive.Orm/Orm/Building/Builders/AttributeProcessor.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,25 @@ public void Process(HierarchyDef hierarchyDef, FieldDef fieldDef, KeyAttribute a
5656
"attribute.Position");
5757

5858
var keyField = new KeyField(fieldDef.Name, attribute.Direction);
59+
var hierarchyDefKeyFields = hierarchyDef.KeyFields;
5960

60-
if (hierarchyDef.KeyFields.Count > attribute.Position) {
61-
var current = hierarchyDef.KeyFields[attribute.Position];
62-
if (current != null) {
61+
if (hierarchyDefKeyFields.Count > attribute.Position) {
62+
var current = hierarchyDefKeyFields[attribute.Position];
63+
if (current != default) {
6364
throw new DomainBuilderException(string.Format(Strings.ExKeyFieldsXAndXHaveTheSamePositionX, current.Name,
6465
fieldDef.Name, attribute.Position));
6566
}
6667

67-
hierarchyDef.KeyFields[attribute.Position] = keyField;
68+
hierarchyDefKeyFields[attribute.Position] = keyField;
6869
}
6970
else {
70-
// Adding null stubs for not yet processed key fields
71-
while (hierarchyDef.KeyFields.Count < attribute.Position) {
72-
hierarchyDef.KeyFields.Add(null);
71+
// Adding default stubs for not yet processed key fields
72+
while (hierarchyDefKeyFields.Count < attribute.Position) {
73+
hierarchyDefKeyFields.Add(default);
7374
}
7475

7576
// Finally adding target key field at the specified position
76-
hierarchyDef.KeyFields.Add(keyField);
77+
hierarchyDefKeyFields.Add(keyField);
7778
}
7879
}
7980

Orm/Xtensive.Orm/Orm/Building/Definitions/HierarchyDef.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed class HierarchyDef : Node
2525
/// <summary>
2626
/// Gets the fields that are included in the key for this hierarchy.
2727
/// </summary>
28-
public List<KeyField> KeyFields { get; private set; }
28+
public List<KeyField> KeyFields { get; } = new(WellKnown.MaxKeyFieldNumber);
2929

3030
/// <summary>
3131
/// Gets the <see cref="InheritanceSchema"/> for this hierarchy.
@@ -58,9 +58,8 @@ public sealed class HierarchyDef : Node
5858
internal HierarchyDef(TypeDef root)
5959
{
6060
Root = root;
61-
KeyFields = new List<KeyField>(WellKnown.MaxKeyFieldNumber);
6261
IsClustered = true;
6362
KeyGeneratorKind = KeyGeneratorKind.Default;
6463
}
6564
}
66-
}
65+
}

Orm/Xtensive.Orm/Orm/Building/FixupActionProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void Process(AddPrimaryIndexAction action)
180180

181181
var hierarchyDef = context.ModelDef.FindHierarchy(hierarchyRoot);
182182

183-
foreach (KeyField pair in hierarchyDef.KeyFields)
183+
foreach (var pair in hierarchyDef.KeyFields)
184184
generatedIndex.KeyFields.Add(pair.Name, pair.Direction);
185185

186186
// Check if user added secondary index equal to auto-generated primary index

Orm/Xtensive.Orm/Orm/Building/ModelInspector.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static void Inspect(BuildingContext context, HierarchyDef hierarchyDef)
200200
}
201201

202202
// Should TypeId field be added to key fields?
203-
if (hierarchyDef.IncludeTypeId && hierarchyDef.KeyFields.Find(f => f.Name == WellKnown.TypeIdFieldName) == null) {
203+
if (hierarchyDef.IncludeTypeId && hierarchyDef.KeyFields.All(f => f.Name != WellKnown.TypeIdFieldName)) {
204204
context.ModelInspectionResult.Register(new AddTypeIdToKeyFieldsAction(hierarchyDef));
205205
}
206206

Orm/Xtensive.Orm/Orm/Building/Validator.cs

+16-25
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// Created by: Dmitri Maximov
55
// Created: 2007.09.12
66

7-
using System;
8-
using System.Collections.Generic;
97
using System.Text.RegularExpressions;
108
using Xtensive.Orm.Building.Definitions;
119
using Xtensive.Orm.Internals;
@@ -14,12 +12,13 @@
1412

1513
namespace Xtensive.Orm.Building
1614
{
17-
internal class Validator
15+
internal class Validator(IEnumerable<Type> validFieldTypes)
1816
{
19-
private readonly HashSet<Type> validFieldTypes;
20-
private readonly Regex columnNamingRule;
21-
private readonly Regex typeNamingRule;
22-
private readonly Regex fieldNamingRule;
17+
private static readonly Regex ColumnNamingRule = new(@"^[\w][\w\-\.]*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
18+
private readonly Regex TypeNamingRule = new(@"^[\w][\w\-\.\(\),]*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
19+
private readonly Regex FieldNamingRule = new(@"^[\w][\w\-\.]*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
20+
21+
private readonly HashSet<Type> validFieldTypes = new(validFieldTypes) { WellKnownOrmTypes.Key };
2322

2423
/// <summary>
2524
/// Determines whether the specified name is valid.
@@ -41,13 +40,13 @@ public void ValidateName(string name, ValidationRule rule)
4140
case ValidationRule.Type:
4241
case ValidationRule.Schema:
4342
case ValidationRule.Database:
44-
namingRule = typeNamingRule;
43+
namingRule = TypeNamingRule;
4544
break;
4645
case ValidationRule.Field:
47-
namingRule = fieldNamingRule;
46+
namingRule = FieldNamingRule;
4847
break;
4948
case ValidationRule.Column:
50-
namingRule = columnNamingRule;
49+
namingRule = ColumnNamingRule;
5150
break;
5251
default:
5352
throw new ArgumentOutOfRangeException();
@@ -257,17 +256,6 @@ internal void EnsureIsNullable(Type valueType)
257256
}
258257
}
259258

260-
// Type initializer
261-
262-
public Validator(IEnumerable<Type> validFieldTypes)
263-
{
264-
columnNamingRule = new Regex(@"^[\w][\w\-\.]*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
265-
typeNamingRule = new Regex(@"^[\w][\w\-\.\(\),]*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
266-
fieldNamingRule = new Regex(@"^[\w][\w\-\.]*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
267-
268-
this.validFieldTypes = new HashSet<Type>(validFieldTypes) {WellKnownOrmTypes.Key};
269-
}
270-
271259
public void ValidateHierarchyEquality(TypeDef @interface, HierarchyDef first, HierarchyDef second)
272260
{
273261
// TypeId mode must match
@@ -277,17 +265,20 @@ public void ValidateHierarchyEquality(TypeDef @interface, HierarchyDef first, Hi
277265
@interface.Name, first.Root.Name, second.Root.Name));
278266
}
279267

268+
var firstKeyFields = first.KeyFields;
269+
var secondKeyFields = second.KeyFields;
270+
280271
// Number of key fields must match
281-
if (first.KeyFields.Count != second.KeyFields.Count) {
272+
if (firstKeyFields.Count != secondKeyFields.Count) {
282273
throw new DomainBuilderException(string.Format(
283274
Strings.ExImplementorsOfXInterfaceBelongToHierarchiesWithDifferentKeyStructureYZ,
284275
@interface.Name, first.Root.Name, second.Root.Name));
285276
}
286277

287278
// Type of each key field must match
288-
for (var i = 0; i < first.KeyFields.Count; i++) {
289-
var masterField = first.Root.Fields[first.KeyFields[i].Name];
290-
var candidateField = second.Root.Fields[second.KeyFields[i].Name];
279+
for (var i = 0; i < firstKeyFields.Count; i++) {
280+
var masterField = first.Root.Fields[firstKeyFields[i].Name];
281+
var candidateField = second.Root.Fields[secondKeyFields[i].Name];
291282
if (masterField.ValueType != candidateField.ValueType) {
292283
throw new DomainBuilderException(string.Format(
293284
Strings.ExImplementorsOfXInterfaceBelongToHierarchiesWithDifferentKeyStructureYZ,

Orm/Xtensive.Orm/Orm/Internals/ReferentialIntegrity/RemovalContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void Dispose()
144144
processor.Context = parent;
145145
}
146146

147-
147+
148148
// Constructors
149149

150150
public RemovalContext(RemovalProcessor processor)
@@ -153,4 +153,4 @@ public RemovalContext(RemovalProcessor processor)
153153
parent = processor.Context;
154154
}
155155
}
156-
}
156+
}

Orm/Xtensive.Orm/Orm/Model/KeyField.cs

+6-45
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,12 @@
44
// Created by: Dmitri Maximov
55
// Created: 2007.12.28
66

7-
using System;
87
using Xtensive.Core;
98

9+
namespace Xtensive.Orm.Model;
1010

11-
namespace Xtensive.Orm.Model
12-
{
13-
/// <summary>
14-
/// Describes a field that is a part of a primary key.
15-
/// </summary>
16-
[Serializable]
17-
public sealed class KeyField : Node
18-
{
19-
/// <summary>
20-
/// Gets or sets the direction.
21-
/// </summary>
22-
public Direction Direction { get; private set; }
23-
24-
/// <inheritdoc/>
25-
public override int GetHashCode() => HashCode.Combine(Name, Direction);
26-
27-
/// <inheritdoc/>
28-
public override bool Equals(object obj) =>
29-
ReferenceEquals(this, obj)
30-
|| obj is KeyField kf && Name == kf.Name && Direction == kf.Direction;
31-
32-
33-
// Constructors
34-
35-
/// <summary>
36-
/// Initializes a new instance of this class.
37-
/// </summary>
38-
/// <param name="name">The name.</param>
39-
public KeyField(string name)
40-
: this(name, Direction.Positive)
41-
{
42-
}
43-
44-
/// <summary>
45-
/// Initializes a new instance of the <see cref="KeyField"/> class.
46-
/// </summary>
47-
/// <param name="name">The name.</param>
48-
/// <param name="direction">The direction.</param>
49-
public KeyField(string name, Direction direction) : base(name)
50-
{
51-
Direction = direction;
52-
}
53-
}
54-
}
11+
/// <summary>
12+
/// Describes a field that is a part of a primary key.
13+
/// </summary>
14+
[Serializable]
15+
public record struct KeyField(string Name, Direction Direction = Direction.Positive);

0 commit comments

Comments
 (0)