1- // Copyright (C) 2008-2020 Xtensive LLC.
1+ // Copyright (C) 2008-2022 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
55// Created: 2008.11.03
66
77using System ;
88using System . Collections . Generic ;
9- using Xtensive . Collections ;
109
1110
1211namespace Xtensive . Orm . Internals
@@ -16,15 +15,14 @@ namespace Xtensive.Orm.Internals
1615 /// </summary>
1716 public sealed class EntityChangeRegistry : SessionBound
1817 {
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 ;
18+ private readonly HashSet < EntityState > @new = new ( ) ;
19+ private readonly HashSet < EntityState > modified = new ( ) ;
20+ private readonly HashSet < EntityState > removed = new ( ) ;
2321
2422 /// <summary>
2523 /// Gets the number of registered entities.
2624 /// </summary>
27- public int Count { get { return count ; } }
25+ public int Count { get ; private set ; }
2826
2927 /// <summary>
3028 /// Registers the specified item.
@@ -34,67 +32,61 @@ internal void Register(EntityState item)
3432 {
3533 // Remove-create sequences fix for Issue 690
3634 if ( item . PersistenceState == PersistenceState . New && removed . Contains ( item ) ) {
37- removed . Remove ( item ) ;
38- count -- ;
35+ _ = removed . Remove ( item ) ;
36+ Count -- ;
3937 if ( item . DifferentialTuple . Difference == null ) {
4038 item . SetPersistenceState ( PersistenceState . Synchronized ) ;
4139 return ;
4240 }
4341 item . SetPersistenceState ( PersistenceState . Modified ) ;
4442 }
4543 else if ( item . PersistenceState == PersistenceState . Removed && @new . Contains ( item ) ) {
46- @new . Remove ( item ) ;
47- count -- ;
44+ _ = @new . Remove ( item ) ;
45+ Count -- ;
4846 return ;
4947 }
5048 else if ( item . PersistenceState == PersistenceState . Removed && modified . Contains ( item ) ) {
51- modified . Remove ( item ) ;
52- count -- ;
49+ _ = modified . Remove ( item ) ;
50+ Count -- ;
5351 }
5452
5553 var container = GetContainer ( item . PersistenceState ) ;
56- if ( container . Add ( item ) )
57- count ++ ;
54+ if ( container . Add ( item ) ) {
55+ Count ++ ;
56+ }
5857 }
5958
6059 /// <summary>
6160 /// Gets the items with specified <paramref name="state"/>.
6261 /// </summary>
6362 /// <param name="state">The state of items to get.</param>
6463 /// <returns>The sequence of items with specified state.</returns>
65- public IEnumerable < EntityState > GetItems ( PersistenceState state )
66- {
67- foreach ( var item in GetContainer ( state ) )
68- yield return item ;
69- }
64+ public RegistryItems < EntityState > GetItems ( in PersistenceState state ) =>
65+ new ( GetContainer ( state ) ) ;
7066
7167 /// <summary>
7268 /// Clears the registry.
7369 /// </summary>
7470 public void Clear ( )
7571 {
76- count = 0 ;
72+ Count = 0 ;
7773 @new . Clear ( ) ;
7874 modified . Clear ( ) ;
7975 removed . Clear ( ) ;
8076 }
8177
8278 /// <exception cref="ArgumentOutOfRangeException"><paramref name="state"/> is out of range.</exception>
83- private HashSet < EntityState > GetContainer ( PersistenceState state )
79+ private HashSet < EntityState > GetContainer ( in PersistenceState state )
8480 {
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- }
81+ return state switch {
82+ PersistenceState . New => @new ,
83+ PersistenceState . Modified => modified ,
84+ PersistenceState . Removed => removed ,
85+ _ => throw new ArgumentOutOfRangeException ( nameof ( state ) ) ,
86+ } ;
9587 }
9688
97-
89+
9890 // Constructors
9991
10092 /// <summary>
0 commit comments