@@ -56,8 +56,8 @@ public Identifier(EntityState entityState, AssociationInfo association)
5656 }
5757 }
5858
59- private readonly IDictionary < Identifier , List < EntityState > > removedReferences = new Dictionary < Identifier , List < EntityState > > ( ) ;
60- private readonly IDictionary < Identifier , List < EntityState > > addedReferences = new Dictionary < Identifier , List < EntityState > > ( ) ;
59+ private readonly IDictionary < Identifier , HashSet < EntityState > > removedReferences = new Dictionary < Identifier , HashSet < EntityState > > ( ) ;
60+ private readonly IDictionary < Identifier , HashSet < EntityState > > addedReferences = new Dictionary < Identifier , HashSet < EntityState > > ( ) ;
6161 private readonly object accessGuard = new object ( ) ;
6262
6363 public int RemovedReferencesCount { get { return removedReferences . Values . Sum ( el => el . Count ) ; } }
@@ -73,7 +73,7 @@ public IEnumerable<EntityState> GetRemovedReferencesTo(EntityState target, Assoc
7373 return Enumerable . Empty < EntityState > ( ) ;
7474
7575 var key = MakeKey ( target , association ) ;
76- List < EntityState > removedMap ;
76+ HashSet < EntityState > removedMap ;
7777 if ( removedReferences . TryGetValue ( key , out removedMap ) )
7878 return removedMap ;
7979 return EnumerableUtils < EntityState > . Empty ;
@@ -88,7 +88,7 @@ public IEnumerable<EntityState> GetAddedReferenceTo(EntityState target, Associat
8888 return Enumerable . Empty < EntityState > ( ) ;
8989
9090 var key = MakeKey ( target , association ) ;
91- List < EntityState > removedMap ;
91+ HashSet < EntityState > removedMap ;
9292 if ( addedReferences . TryGetValue ( key , out removedMap ) )
9393 return removedMap ;
9494 return EnumerableUtils < EntityState > . Empty ;
@@ -137,7 +137,7 @@ private void RegisterChange(EntityState referencedState, EntityState referencing
137137
138138 private void RegisterRemoveInternal ( Identifier oldKey , EntityState referencingState )
139139 {
140- List < EntityState > references ;
140+ HashSet < EntityState > references ;
141141 if ( addedReferences . TryGetValue ( oldKey , out references ) ) {
142142 if ( references . Remove ( referencingState ) ) {
143143 if ( references . Count == 0 )
@@ -146,30 +146,28 @@ private void RegisterRemoveInternal(Identifier oldKey, EntityState referencingSt
146146 }
147147 }
148148 if ( removedReferences . TryGetValue ( oldKey , out references ) ) {
149- if ( references . Contains ( referencingState ) )
149+ if ( ! references . Add ( referencingState ) )
150150 throw new InvalidOperationException ( Strings . ExReferenceRregistrationErrorReferenceRemovalIsAlreadyRegistered ) ;
151- references . Add ( referencingState ) ;
152151 return ;
153152 }
154- removedReferences . Add ( oldKey , new List < EntityState > { referencingState } ) ;
153+ removedReferences . Add ( oldKey , new HashSet < EntityState > { referencingState } ) ;
155154 }
156155
157156 private void RegisterAddInternal ( Identifier newKey , EntityState referencingState )
158157 {
159- List < EntityState > references ;
158+ HashSet < EntityState > references ;
160159 if ( removedReferences . TryGetValue ( newKey , out references ) ) {
161160 if ( references . Remove ( referencingState ) )
162161 if ( references . Count == 0 )
163162 removedReferences . Remove ( newKey ) ;
164163 return ;
165164 }
166165 if ( addedReferences . TryGetValue ( newKey , out references ) ) {
167- if ( references . Contains ( referencingState ) )
166+ if ( ! references . Add ( referencingState ) )
168167 throw new InvalidOperationException ( Strings . ExReferenceRegistrationErrorReferenceAdditionIsAlreadyRegistered ) ;
169- references . Add ( referencingState ) ;
170168 return ;
171169 }
172- addedReferences . Add ( newKey , new List < EntityState > { referencingState } ) ;
170+ addedReferences . Add ( newKey , new HashSet < EntityState > { referencingState } ) ;
173171 }
174172
175173 private Identifier MakeKey ( EntityState state , AssociationInfo association )
0 commit comments