Small follow up to 8ee3d45

- rename `containsIndexers` to `doNotCache` in `ExpressionHelper`
This commit is contained in:
Doug Bunting 2017-02-10 16:46:55 -08:00
parent fc40985412
commit 4bddb5ff1b
1 changed files with 8 additions and 8 deletions

View File

@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
// Determine size of string needed (length) and number of segments it contains (segmentCount). Put another // Determine size of string needed (length) and number of segments it contains (segmentCount). Put another
// way, segmentCount tracks the number of times the loop below should iterate. This avoids adding ".model" // way, segmentCount tracks the number of times the loop below should iterate. This avoids adding ".model"
// and / or an extra leading "." and then removing them after the loop. Other information collected in this // and / or an extra leading "." and then removing them after the loop. Other information collected in this
// first loop helps with length and segmentCount adjustments. containsIndexers is somewhat separate: If // first loop helps with length and segmentCount adjustments. doNotCache is somewhat separate: If
// true, expression strings are not cached for the expression. // true, expression strings are not cached for the expression.
// //
// After the corrections below the first loop, length is usually exactly the size of the returned string. // After the corrections below the first loop, length is usually exactly the size of the returned string.
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
// expressions multiple times or saving indexer strings can get expensive. Optimizing for the common case // expressions multiple times or saving indexer strings can get expensive. Optimizing for the common case
// of a collection (not a dictionary) with less than 100 elements. If that assumption proves to be // of a collection (not a dictionary) with less than 100 elements. If that assumption proves to be
// incorrect, the StringBuilder will be enlarged but hopefully just once. // incorrect, the StringBuilder will be enlarged but hopefully just once.
var containsIndexers = false; var doNotCache = false;
var lastIsModel = false; var lastIsModel = false;
var length = 0; var length = 0;
var segmentCount = 0; var segmentCount = 0;
@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
case ExpressionType.Call: case ExpressionType.Call:
// Will exit loop if at Method().Property or [i,j].Property. In that case (like [i].Property), // Will exit loop if at Method().Property or [i,j].Property. In that case (like [i].Property),
// don't cache and don't remove ".Model" (if that's .Property). // don't cache and don't remove ".Model" (if that's .Property).
containsIndexers = true; doNotCache = true;
lastIsModel = false; lastIsModel = false;
var methodExpression = (MethodCallExpression)part; var methodExpression = (MethodCallExpression)part;
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
case ExpressionType.ArrayIndex: case ExpressionType.ArrayIndex:
var binaryExpression = (BinaryExpression)part; var binaryExpression = (BinaryExpression)part;
containsIndexers = true; doNotCache = true;
lastIsModel = false; lastIsModel = false;
length += "[99]".Length; length += "[99]".Length;
part = binaryExpression.Left; part = binaryExpression.Left;
@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
Debug.Assert(segmentCount >= 0); Debug.Assert(segmentCount >= 0);
if (segmentCount == 0) if (segmentCount == 0)
{ {
Debug.Assert(!containsIndexers); Debug.Assert(!doNotCache);
if (expressionTextCache != null) if (expressionTextCache != null)
{ {
expressionTextCache.Entries.TryAdd(expression, string.Empty); expressionTextCache.Entries.TryAdd(expression, string.Empty);
@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
switch (part.NodeType) switch (part.NodeType)
{ {
case ExpressionType.Call: case ExpressionType.Call:
Debug.Assert(containsIndexers); Debug.Assert(doNotCache);
var methodExpression = (MethodCallExpression)part; var methodExpression = (MethodCallExpression)part;
InsertIndexerInvocationText(builder, methodExpression.Arguments.Single(), expression); InsertIndexerInvocationText(builder, methodExpression.Arguments.Single(), expression);
@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
break; break;
case ExpressionType.ArrayIndex: case ExpressionType.ArrayIndex:
Debug.Assert(containsIndexers); Debug.Assert(doNotCache);
var binaryExpression = (BinaryExpression)part; var binaryExpression = (BinaryExpression)part;
InsertIndexerInvocationText(builder, binaryExpression.Right, expression); InsertIndexerInvocationText(builder, binaryExpression.Right, expression);
@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
Debug.Assert(segmentCount == 0); Debug.Assert(segmentCount == 0);
expressionText = builder.ToString(); expressionText = builder.ToString();
if (expressionTextCache != null && !containsIndexers) if (expressionTextCache != null && !doNotCache)
{ {
expressionTextCache.Entries.TryAdd(expression, expressionText); expressionTextCache.Entries.TryAdd(expression, expressionText);
} }