StyletIoC: Speed up GetAll calls slightly

This commit is contained in:
Antony Male 2014-11-29 18:23:01 +00:00
parent 788c50de47
commit aa129f54cd
1 changed files with 3 additions and 2 deletions

View File

@ -52,8 +52,9 @@ namespace StyletIoC.Internal.Registrations
if (this.expression != null)
return this.expression;
var listNew = Expression.New(this.Type);
var instanceExpressions = this.parentContext.GetAllRegistrations(this.Type.GenericTypeArguments[0], this.Key, false).Select(x => x.GetInstanceExpression(registrationContext));
var instanceExpressions = this.parentContext.GetAllRegistrations(this.Type.GenericTypeArguments[0], this.Key, false).Select(x => x.GetInstanceExpression(registrationContext)).ToArray();
var listCtor = this.Type.GetConstructor(new[] { typeof(int) }); // ctor which takes capacity
var listNew = Expression.New(listCtor, Expression.Constant(instanceExpressions.Length));
Expression list = instanceExpressions.Any() ? (Expression)Expression.ListInit(listNew, instanceExpressions) : listNew;
Interlocked.CompareExchange(ref this.expression, list, null);