@@ -316,6 +316,55 @@ private IRegistry<string, IPolicySet> Get(Type type)
316316
317317 #region Registration manipulation
318318
319+
320+ // Register new and return overridden registration
321+ internal IPolicySet AppendNew ( Type type , string name , InternalRegistration registration )
322+ {
323+ var collisions = 0 ;
324+ var hashCode = ( type ? . GetHashCode ( ) ?? 0 ) & 0x7FFFFFFF ;
325+ var targetBucket = hashCode % _registrations . Buckets . Length ;
326+ lock ( _syncRoot )
327+ {
328+ for ( var i = _registrations . Buckets [ targetBucket ] ; i >= 0 ; i = _registrations . Entries [ i ] . Next )
329+ {
330+ ref var candidate = ref _registrations . Entries [ i ] ;
331+ if ( candidate . HashCode != hashCode ||
332+ candidate . Key != type )
333+ {
334+ collisions ++ ;
335+ continue ;
336+ }
337+
338+ if ( candidate . Value is HashRegistry registry )
339+ {
340+ candidate . Value = new LinkedRegistry ( registry ) ;
341+ }
342+
343+ var existing = candidate . Value as LinkedRegistry ;
344+ Debug . Assert ( null != existing ) ;
345+
346+ existing . Append ( name , registration ) ;
347+
348+ return null ;
349+ }
350+
351+ if ( _registrations . RequireToGrow || ListToHashCutPoint < collisions )
352+ {
353+ _registrations = new Registrations ( _registrations ) ;
354+ targetBucket = hashCode % _registrations . Buckets . Length ;
355+ }
356+
357+ ref var entry = ref _registrations . Entries [ _registrations . Count ] ;
358+ entry . HashCode = hashCode ;
359+ entry . Next = _registrations . Buckets [ targetBucket ] ;
360+ entry . Key = type ;
361+ entry . Value = new LinkedRegistry ( name , registration ) ;
362+ _registrations . Buckets [ targetBucket ] = _registrations . Count ++ ;
363+
364+ return null ;
365+ }
366+ }
367+
319368 // Register new and return overridden registration
320369 private IPolicySet AddOrUpdate ( Type type , string name , InternalRegistration registration )
321370 {
0 commit comments