@@ -162,15 +162,67 @@ partial class Composition
162162 [MethodImpl (MethodImplOptions .AggressiveInlining )]
163163 public object Resolve (Type type )
164164 {
165+ var index = (int )(_bucketSize * ((uint )RuntimeHelpers .GetHashCode (type ) % 1 ));
166+ ref var pair = ref _buckets [index ];
167+ return pair .Key == type ? pair .Value .Resolve (this ) : Resolve (type , index );
168+ }
169+
170+ [MethodImpl (MethodImplOptions .NoInlining )]
171+ private object Resolve (Type type , int index )
172+ {
173+ var finish = index + _bucketSize ;
174+ while (++ index < finish )
175+ {
176+ ref var pair = ref _buckets [index ];
177+ if (pair .Key == type )
178+ {
179+ return pair .Value .Resolve (this );
180+ }
181+ }
182+
165183 throw new InvalidOperationException ($" {CannotResolveMessage } {OfTypeMessage } {type }." );
166184 }
167185
168186 [MethodImpl (MethodImplOptions .AggressiveInlining )]
169187 public object Resolve (Type type , object ? tag )
170188 {
189+ var index = (int )(_bucketSize * ((uint )RuntimeHelpers .GetHashCode (type ) % 1 ));
190+ ref var pair = ref _buckets [index ];
191+ return pair .Key == type ? pair .Value .ResolveByTag (this , tag ) : Resolve (type , tag , index );
192+ }
193+
194+ [MethodImpl (MethodImplOptions .NoInlining )]
195+ private object Resolve (Type type , object ? tag , int index )
196+ {
197+ var finish = index + _bucketSize ;
198+ while (++ index < finish )
199+ {
200+ ref var pair = ref _buckets [index ];
201+ if (pair .Key == type )
202+ {
203+ return pair .Value .ResolveByTag (this , tag );
204+ }
205+ }
206+
171207 throw new InvalidOperationException ($" {CannotResolveMessage } \" {tag }\" {OfTypeMessage } {type }." );
172208 }
173209
210+ private readonly static int _bucketSize ;
211+ private readonly static Pair <Type , IResolver <Composition , object >>[] _buckets ;
212+
213+ static Composition ()
214+ {
215+ var valResolver_0000 = new Resolver_0000 ();
216+ Resolver <Owned <IService >>.Value = valResolver_0000 ;
217+ _buckets = Buckets <Type , IResolver <Composition , object >>.Create (
218+ 1 ,
219+ out _bucketSize ,
220+ new Pair <Type , IResolver <Composition , object >>[1 ]
221+ {
222+ new Pair <Type , IResolver <Composition , object >>(typeof (Owned <IService >), valResolver_0000 )
223+ });
224+ }
225+
174226 private const string CannotResolveMessage = " Cannot resolve composition root " ;
175227 private const string OfTypeMessage = " of type " ;
176228
@@ -188,6 +240,35 @@ partial class Composition
188240 throw new InvalidOperationException ($" {CannotResolveMessage }\" {tag }\" {OfTypeMessage }{typeof (T )}." );
189241 }
190242 }
243+
244+ private sealed class Resolver_0000 : Resolver <Owned <IService >>, IResolver <Composition , object >
245+ {
246+ public override Owned <IService > Resolve (Composition composition )
247+ {
248+ return composition .Root ;
249+ }
250+
251+ public override Owned <IService > ResolveByTag (Composition composition , object tag )
252+ {
253+ switch (tag )
254+ {
255+ case null :
256+ return composition .Root ;
257+
258+ default :
259+ return base .ResolveByTag (composition , tag );
260+ }
261+ }
262+ object IResolver<Composition, object>.Resolve (Composition composition )
263+ {
264+ return Resolve (composition );
265+ }
266+
267+ object IResolver<Composition, object>.ResolveByTag (Composition composition , object tag )
268+ {
269+ return ResolveByTag (composition , tag );
270+ }
271+ }
191272}
192273```
193274
0 commit comments