Skip to content

Commit 97f8eda

Browse files
committed
Revert "Optimize GetChangedEntities()"
This reverts commit af4427e.
1 parent 88f9a09 commit 97f8eda

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2008-2022 Xtensive LLC.
1+
// Copyright (C) 2008-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: Dmitri Maximov
@@ -16,14 +16,15 @@ namespace Xtensive.Orm.Internals
1616
/// </summary>
1717
public sealed class EntityChangeRegistry : SessionBound
1818
{
19-
private readonly HashSet<EntityState> @new = new();
20-
private readonly HashSet<EntityState> modified = new();
21-
private readonly HashSet<EntityState> removed = new();
19+
private readonly HashSet<EntityState> @new = new HashSet<EntityState>();
20+
private readonly HashSet<EntityState> modified = new HashSet<EntityState>();
21+
private readonly HashSet<EntityState> removed = new HashSet<EntityState>();
22+
private int count;
2223

2324
/// <summary>
2425
/// Gets the number of registered entities.
2526
/// </summary>
26-
public int Count { get; private set; }
27+
public int Count { get { return count; } }
2728

2829
/// <summary>
2930
/// Registers the specified item.
@@ -34,7 +35,7 @@ internal void Register(EntityState item)
3435
// Remove-create sequences fix for Issue 690
3536
if (item.PersistenceState == PersistenceState.New && removed.Contains(item)) {
3637
removed.Remove(item);
37-
Count--;
38+
count--;
3839
if (item.DifferentialTuple.Difference == null) {
3940
item.SetPersistenceState(PersistenceState.Synchronized);
4041
return;
@@ -43,17 +44,17 @@ internal void Register(EntityState item)
4344
}
4445
else if (item.PersistenceState == PersistenceState.Removed && @new.Contains(item)) {
4546
@new.Remove(item);
46-
Count--;
47+
count--;
4748
return;
4849
}
4950
else if (item.PersistenceState == PersistenceState.Removed && modified.Contains(item)) {
5051
modified.Remove(item);
51-
Count--;
52+
count--;
5253
}
5354

5455
var container = GetContainer(item.PersistenceState);
5556
if (container.Add(item))
56-
Count++;
57+
count++;
5758
}
5859

5960
/// <summary>
@@ -72,20 +73,26 @@ public IEnumerable<EntityState> GetItems(PersistenceState state)
7273
/// </summary>
7374
public void Clear()
7475
{
75-
Count = 0;
76+
count = 0;
7677
@new.Clear();
7778
modified.Clear();
7879
removed.Clear();
7980
}
8081

8182
/// <exception cref="ArgumentOutOfRangeException"><paramref name="state"/> is out of range.</exception>
82-
internal HashSet<EntityState> GetContainer(PersistenceState state) =>
83-
state switch {
84-
PersistenceState.New => @new,
85-
PersistenceState.Modified => modified,
86-
PersistenceState.Removed => removed,
87-
_ => throw new ArgumentOutOfRangeException(nameof(state))
88-
};
83+
private HashSet<EntityState> GetContainer(PersistenceState state)
84+
{
85+
switch (state) {
86+
case PersistenceState.New:
87+
return @new;
88+
case PersistenceState.Modified:
89+
return modified;
90+
case PersistenceState.Removed:
91+
return removed;
92+
default:
93+
throw new ArgumentOutOfRangeException("state");
94+
}
95+
}
8996

9097

9198
// Constructors

Orm/Xtensive.Orm/Orm/Services/DirectSessionAccessor.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public IDisposable ChangeSessionHandler(SessionHandler newHandler)
5656
/// An object implementing <see cref="IDisposable"/> which
5757
/// disposal will restore previous state of
5858
/// <see cref="Session.Transaction"/> property;
59-
/// <see langword="null" />, if <see cref="Session.Transaction"/>
59+
/// <see langword="null" />, if <see cref="Session.Transaction"/>
6060
/// is already <see langword="null" />.
6161
/// </returns>
6262
public IDisposable NullifySessionTransaction()
@@ -76,12 +76,11 @@ public IDisposable NullifySessionTransaction()
7676
/// </summary>
7777
/// <param name="persistenceState">Type of entity change.</param>
7878
/// <returns><see cref="EntityState"/>s with the specified <paramref name="persistenceState"/>.</returns>
79-
public IEnumerable<EntityState> GetChangedEntities(PersistenceState persistenceState) =>
80-
#if DO_SAFE_COLLECTION_WRAPPER
81-
Session.EntityChangeRegistry.GetItems(persistenceState);
82-
#else
83-
Session.EntityChangeRegistry.GetContainer(persistenceState);
84-
#endif
79+
public IEnumerable<EntityState> GetChangedEntities(PersistenceState persistenceState)
80+
{
81+
return Session.EntityChangeRegistry.GetItems(persistenceState);
82+
}
83+
8584

8685
// Constructors
8786

0 commit comments

Comments
 (0)