Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Small follow up to 8ee3d45
Browse files Browse the repository at this point in the history
- rename `containsIndexers` to `doNotCache` in `ExpressionHelper`
  • Loading branch information
dougbu committed Feb 11, 2017
1 parent fc40985 commit 4bddb5f
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe
// 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"
// 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.
//
// After the corrections below the first loop, length is usually exactly the size of the returned string.
// However when containsIndexers is true, the calculation is approximate because either evaluating indexer
// 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
// incorrect, the StringBuilder will be enlarged but hopefully just once.
var containsIndexers = false;
var doNotCache = false;
var lastIsModel = false;
var length = 0;
var segmentCount = 0;
Expand All @@ -63,7 +63,7 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe
case ExpressionType.Call:
// 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).
containsIndexers = true;
doNotCache = true;
lastIsModel = false;

var methodExpression = (MethodCallExpression)part;
Expand All @@ -84,7 +84,7 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe
case ExpressionType.ArrayIndex:
var binaryExpression = (BinaryExpression)part;

containsIndexers = true;
doNotCache = true;
lastIsModel = false;
length += "[99]".Length;
part = binaryExpression.Left;
Expand Down Expand Up @@ -143,7 +143,7 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe
Debug.Assert(segmentCount >= 0);
if (segmentCount == 0)
{
Debug.Assert(!containsIndexers);
Debug.Assert(!doNotCache);
if (expressionTextCache != null)
{
expressionTextCache.Entries.TryAdd(expression, string.Empty);
Expand All @@ -160,7 +160,7 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe
switch (part.NodeType)
{
case ExpressionType.Call:
Debug.Assert(containsIndexers);
Debug.Assert(doNotCache);
var methodExpression = (MethodCallExpression)part;

InsertIndexerInvocationText(builder, methodExpression.Arguments.Single(), expression);
Expand All @@ -169,7 +169,7 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe
break;

case ExpressionType.ArrayIndex:
Debug.Assert(containsIndexers);
Debug.Assert(doNotCache);
var binaryExpression = (BinaryExpression)part;

InsertIndexerInvocationText(builder, binaryExpression.Right, expression);
Expand Down Expand Up @@ -201,7 +201,7 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe

Debug.Assert(segmentCount == 0);
expressionText = builder.ToString();
if (expressionTextCache != null && !containsIndexers)
if (expressionTextCache != null && !doNotCache)
{
expressionTextCache.Entries.TryAdd(expression, expressionText);
}
Expand Down

0 comments on commit 4bddb5f

Please sign in to comment.