@@ -478,30 +478,23 @@ private IPolicySet GetOrAddGeneric(Type type, string name, Type definition)
478478 var collisions = 0 ;
479479 int hashCode ;
480480 int targetBucket ;
481- var factory = false ;
481+ InternalRegistration factory = null ;
482482
483- if ( null != _parent )
483+ hashCode = ( definition ? . GetHashCode ( ) ?? 0 ) & 0x7FFFFFFF ;
484+ targetBucket = hashCode % _registrations . Buckets . Length ;
485+ for ( var j = _registrations . Buckets [ targetBucket ] ; j >= 0 ; j = _registrations . Entries [ j ] . Next )
484486 {
485- hashCode = ( definition ? . GetHashCode ( ) ?? 0 ) & 0x7FFFFFFF ;
486- targetBucket = hashCode % _registrations . Buckets . Length ;
487- for ( var j = _registrations . Buckets [ targetBucket ] ; j >= 0 ; j = _registrations . Entries [ j ] . Next )
487+ ref var candidate = ref _registrations . Entries [ j ] ;
488+ if ( candidate . HashCode != hashCode || candidate . Key != definition )
488489 {
489- ref var candidate = ref _registrations . Entries [ j ] ;
490- if ( candidate . HashCode != hashCode || candidate . Key != definition )
491- {
492- continue ;
493- }
494-
495- if ( null != candidate . Value ? [ name ] )
496- {
497- factory = true ;
498- break ;
499- }
490+ continue ;
500491 }
501492
502- if ( ! factory ) return _parent . _getGenericRegistration ( type , name , definition ) ;
493+ if ( null != ( factory = ( InternalRegistration ) candidate . Value ? [ name ] ) ) break ;
503494 }
504495
496+ if ( null == factory && null != _parent ) return _parent . _getGenericRegistration ( type , name , definition ) ;
497+
505498 hashCode = ( type ? . GetHashCode ( ) ?? 0 ) & 0x7FFFFFFF ;
506499 targetBucket = hashCode % _registrations . Buckets . Length ;
507500
@@ -527,7 +520,7 @@ private IPolicySet GetOrAddGeneric(Type type, string name, Type definition)
527520 _registrations . Entries [ i ] . Value = existing ;
528521 }
529522
530- return existing . GetOrAdd ( name , ( ) => CreateRegistration ( type , name ) ) ;
523+ return existing . GetOrAdd ( name , ( ) => CreateRegistration ( type , name , factory ) ) ;
531524 }
532525
533526 if ( _registrations . RequireToGrow || ListToHashCutPoint < collisions )
@@ -536,7 +529,7 @@ private IPolicySet GetOrAddGeneric(Type type, string name, Type definition)
536529 targetBucket = hashCode % _registrations . Buckets . Length ;
537530 }
538531
539- var registration = CreateRegistration ( type , name ) ;
532+ var registration = CreateRegistration ( type , name , factory ) ;
540533 ref var entry = ref _registrations . Entries [ _registrations . Count ] ;
541534 entry . HashCode = hashCode ;
542535 entry . Next = _registrations . Buckets [ targetBucket ] ;
0 commit comments