Skip to content

Commit a4b5b6b

Browse files
committed
small things opti
1 parent be1c8ec commit a4b5b6b

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/DryIoc/Container.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ private object ResolveAndCache(int serviceTypeHash, Type serviceType, IfUnresolv
370370
var rules = Rules;
371371
if (!rules.UseInterpretationForTheFirstResolution)
372372
{
373-
// todo: @perf @mem should we introduce the GetInstanceOrDefault to avoid lifting object ToFactoryDelegate, e.g. for InstanceFactory
374373
factoryDelegate = factory.GetDelegateOrDefault(request);
375374
request.ReturnToPool();
376375
if (factoryDelegate == null)
@@ -8648,7 +8647,6 @@ public enum IsRegistryChangePermitted : byte
86488647
Ignored
86498648
}
86508649

8651-
// todo: @perf @memory split by IfUnresolved and separate the Metadata
86528650
/// <summary>Provides optional service resolution details: service key, required service type, what return when service is unresolved,
86538651
/// default value if service is unresolved, custom service value.</summary>
86548652
public sealed class ServiceDetails
@@ -9336,7 +9334,7 @@ internal static readonly RequestFlags InheritedFlags
93369334

93379335
internal static Request CreateForValidation(Container container, ServiceInfo serviceInfo, Request[] depRequestStack)
93389336
{
9339-
var req = RentRequest();
9337+
var req = RentRequestOrNull();
93409338
return req == null
93419339
? req = new Request(container, Empty, 1, 0, depRequestStack, RequestFlags.IsResolutionCall, serviceInfo, serviceInfo.GetActualServiceType(), null)
93429340
: req.SetServiceInfo(container, Empty, 1, 0, depRequestStack, RequestFlags.IsResolutionCall, serviceInfo, serviceInfo.GetActualServiceType(), null);
@@ -9376,10 +9374,9 @@ public static Request CreateResolutionRoot(Container container, Type serviceType
93769374
if (serviceType != null && serviceType.IsOpenGeneric())
93779375
Throw.It(Error.ResolvingOpenGenericServiceTypeIsNotPossible, serviceType);
93789376

9379-
// todo: @mem @perf Could we avoid the allocation of the ServiceInfo details object for ifUnresolved? because it is unlucky path but we spend the memory on it upfront, especially given that ServiceProviderGetServiceShouldThrowIfUnresolved contains the adjusting value anyway???
93809377
object serviceInfo = ifUnresolved == IfUnresolved.Throw ? serviceType : ServiceDetails.Of(ifUnresolved);
93819378

9382-
var req = RentRequest();
9379+
var req = RentRequestOrNull();
93839380
return req == null
93849381
? new Request(container, Empty, 1, 0, null, RequestFlags.IsResolutionCall, serviceInfo, serviceType, null)
93859382
: req.SetServiceInfo(container, Empty, 1, 0, null, RequestFlags.IsResolutionCall, serviceInfo, serviceType, null);
@@ -10142,7 +10139,7 @@ internal Request IsolateRequestChain()
1014210139
}
1014310140

1014410141
private static Request _pooledRequest;
10145-
internal static Request RentRequest() => Interlocked.Exchange(ref _pooledRequest, null);
10142+
internal static Request RentRequestOrNull() => Interlocked.Exchange(ref _pooledRequest, null);
1014610143
internal void ReturnToPool()
1014710144
{
1014810145
if (_pooledRequest == null && (Flags & RequestFlags.DoNotPoolRequest) == 0)

0 commit comments

Comments
 (0)