Skip to content

Commit 3fe1c80

Browse files
authored
Get rid of RegistryItems<> - it is the same as IReadOnlySet (#255)
* Get rid of `RegistryItems<>` - it is the same as `IReadOnlySet` * Make EntitySetChangeRegistry readonly struct * EntitySetChangeRegistry = new() * Make `EntityEventBroker` struct * Fix readonly modifier * Make NonPairedReferenceChangesRegistry struct * [0] instead of .First() * Minor improvements * Make CommandProcessorContextProvider struct * Make KeyMapper struct * Make ReferenceFieldsChangesRegistry struct
1 parent 52e449c commit 3fe1c80

18 files changed

+116
-276
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tab_width = 2
3636

3737
# New line preferences
3838
end_of_line = lf
39-
insert_final_newline = false
39+
insert_final_newline = true
4040

4141
#### .NET Coding Conventions ####
4242
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#net-code-style-settings

Orm/Xtensive.Orm.Tests/Storage/CommandProcessorContextProviderTest.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ protected override void PopulateData()
1919
public void GetContextTest()
2020
{
2121
var session = Session.Demand();
22-
var provider = session.CommandProcessorContextProvider;
23-
var context = provider.ProvideContext();
22+
var context = session.CommandProcessorContextProvider.ProvideContext();
2423

2524
Assert.That(context, Is.Not.Null);
2625
Assert.That(context.AllowPartialExecution, Is.False);
@@ -30,15 +29,14 @@ public void GetContextTest()
3029
Assert.That(context.ProcessingTasks, Is.Not.Null);
3130
Assert.That(context.ProcessingTasks.Count, Is.EqualTo(0));
3231

33-
Assert.That(provider.ProvideContext(), Is.Not.SameAs(provider.ProvideContext()));
32+
Assert.That(session.CommandProcessorContextProvider.ProvideContext(), Is.Not.SameAs(session.CommandProcessorContextProvider.ProvideContext()));
3433
}
3534

3635
[Test]
3736
public void GetContextForPartialExecutionTest()
3837
{
3938
var session = Session.Demand();
40-
var provider = session.CommandProcessorContextProvider;
41-
var context = provider.ProvideContext(true);
39+
var context = session.CommandProcessorContextProvider.ProvideContext(true);
4240

4341
Assert.That(context, Is.Not.Null);
4442
Assert.That(context.AllowPartialExecution, Is.True);
@@ -48,7 +46,7 @@ public void GetContextForPartialExecutionTest()
4846
Assert.That(context.ProcessingTasks, Is.Not.Null);
4947
Assert.That(context.ProcessingTasks.Count, Is.EqualTo(0));
5048

51-
Assert.That(provider.ProvideContext(true), Is.Not.SameAs(provider.ProvideContext(true)));
49+
Assert.That(session.CommandProcessorContextProvider.ProvideContext(true), Is.Not.SameAs(session.CommandProcessorContextProvider.ProvideContext(true)));
5250
}
5351
}
54-
}
52+
}

Orm/Xtensive.Orm/Orm/CommandProcessorContextProvider.cs

+5-14
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010

1111
namespace Xtensive.Orm
1212
{
13-
public sealed class CommandProcessorContextProvider : SessionBound
13+
internal struct CommandProcessorContextProvider()
1414
{
15-
private readonly ConcurrentDictionary<CommandProcessorContext, CommandProcessorContext> providedContexts
16-
= new ConcurrentDictionary<CommandProcessorContext, CommandProcessorContext>();
15+
private readonly ConcurrentDictionary<CommandProcessorContext, CommandProcessorContext> providedContexts = new();
1716

1817
/// <inheritdoc/>
19-
public int AliveContextCount { get { return providedContexts.Count; } }
18+
public int AliveContextCount => providedContexts.Count;
2019

2120
/// <inheritdoc/>
22-
public CommandProcessorContext ProvideContext()
23-
{
24-
return ProvideContext(false);
25-
}
21+
public CommandProcessorContext ProvideContext() => ProvideContext(false);
2622

2723
/// <inheritdoc/>
2824
public CommandProcessorContext ProvideContext(bool allowPartialExecution)
@@ -40,10 +36,5 @@ private void RemoveDisposedContext(object sender, EventArgs args)
4036
providedContexts.TryRemove(context, out _);
4137
context.Disposed -= RemoveDisposedContext;
4238
}
43-
44-
internal CommandProcessorContextProvider(Session session)
45-
: base(session)
46-
{
47-
}
4839
}
49-
}
40+
}

Orm/Xtensive.Orm/Orm/EntityEventBroker.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Xtensive.Orm
1414
/// <summary>
1515
/// Manages events related to <see cref="Entity"/>.
1616
/// </summary>
17-
public sealed class EntityEventBroker
17+
public struct EntityEventBroker
1818
{
1919
private Dictionary<(Key, FieldInfo, object), Delegate> subscribers;
2020

@@ -258,4 +258,4 @@ public void RemapKeys(KeyMapping keyMapping)
258258
}
259259
}
260260
}
261-
}
261+
}

Orm/Xtensive.Orm/Orm/Internals/ChangeRegistries/EntityChangeRegistry.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ internal void Register(EntityState item)
6161
/// </summary>
6262
/// <param name="state">The state of items to get.</param>
6363
/// <returns>The sequence of items with specified state.</returns>
64-
public RegistryItems<EntityState> GetItems(in PersistenceState state) =>
65-
new(GetContainer(state));
64+
public IReadOnlySet<EntityState> GetItems(in PersistenceState state) => GetContainer(state);
6665

6766
/// <summary>
6867
/// Clears the registry.

Orm/Xtensive.Orm/Orm/Internals/ChangeRegistries/EntitySetChangeRegistry.cs

+4-14
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ namespace Xtensive.Orm.Internals
1111
/// <summary>
1212
/// Contains <see cref="EntitySetState"/>s which modified during the bounded session.
1313
/// </summary>
14-
public sealed class EntitySetChangeRegistry : SessionBound
14+
public readonly struct EntitySetChangeRegistry()
1515
{
1616
private readonly HashSet<EntitySetState> modifiedEntitySets = new();
1717

1818
/// <summary>
1919
/// Count of registered <see cref="EntitySetState"/>.
2020
/// </summary>
21-
public int Count { get { return modifiedEntitySets.Count; } }
21+
public int Count => modifiedEntitySets.Count;
2222

2323
/// <summary>
2424
/// Register the specified <see cref="EntitySetState"/>.
@@ -30,21 +30,11 @@ public sealed class EntitySetChangeRegistry : SessionBound
3030
/// Gets all registered items.
3131
/// </summary>
3232
/// <returns></returns>
33-
public RegistryItems<EntitySetState> GetItems() => new(modifiedEntitySets);
33+
public IReadOnlySet<EntitySetState> GetItems() => modifiedEntitySets;
3434

3535
/// <summary>
3636
/// Clears the registry.
3737
/// </summary>
38-
public void Clear() => modifiedEntitySets.Clear();
39-
40-
/// <summary>
41-
/// Initializes a new instance of this class.
42-
/// </summary>
43-
/// <param name="session"><see cref="Session"/>, to which current instance
44-
/// is bound.</param>
45-
public EntitySetChangeRegistry(Session session)
46-
: base(session)
47-
{
48-
}
38+
public void Clear() => modifiedEntitySets?.Clear();
4939
}
5040
}

0 commit comments

Comments
 (0)