From 8422faf55a317439f023c596c0d8e77a9e59bc5f Mon Sep 17 00:00:00 2001 From: Felix Huang Date: Wed, 12 Jul 2023 17:00:59 -0700 Subject: [PATCH] Add StringIntern for Item and Property Functions. --- src/Build/Evaluation/Expander.cs | 4 ++-- src/Build/Evaluation/ExpressionShredder.cs | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Build/Evaluation/Expander.cs b/src/Build/Evaluation/Expander.cs index 075090e0f9a..6e812c58767 100644 --- a/src/Build/Evaluation/Expander.cs +++ b/src/Build/Evaluation/Expander.cs @@ -3315,7 +3315,7 @@ internal static Function ExtractPropertyFunction( ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionStaticMethodSyntax", expressionFunction, String.Empty); } - var typeName = expressionRoot.Slice(1, typeEndIndex - 1).ToString(); + var typeName = Strings.WeakIntern(expressionRoot.Slice(1, typeEndIndex - 1)); var methodStartIndex = typeEndIndex + 1; if (expressionRoot.Length > methodStartIndex + 2 && expressionRoot[methodStartIndex] == ':' && expressionRoot[methodStartIndex + 1] == ':') @@ -3373,7 +3373,7 @@ internal static Function ExtractPropertyFunction( var rootEndIndex = expressionRoot.IndexOf('.'); // If this is an instance function rather than a static, then we'll capture the name of the property referenced - var functionReceiver = expressionRoot.Slice(0, rootEndIndex).Trim().ToString(); + var functionReceiver = Strings.WeakIntern(expressionRoot.Slice(0, rootEndIndex).Trim()); // If propertyValue is null (we're not recursing), then we're expecting a valid property name if (propertyValue == null && !IsValidPropertyName(functionReceiver)) diff --git a/src/Build/Evaluation/ExpressionShredder.cs b/src/Build/Evaluation/ExpressionShredder.cs index c555a10d0e2..360843f9b58 100644 --- a/src/Build/Evaluation/ExpressionShredder.cs +++ b/src/Build/Evaluation/ExpressionShredder.cs @@ -156,10 +156,7 @@ internal static List GetReferencedItemExpressions(string // Grab the name, but continue to verify it's a well-formed expression // before we store it. - string name = expression.Substring(startOfName, i - startOfName); - - // return the item that we're working with - string itemName = name; + string itemName = Microsoft.NET.StringTools.Strings.WeakIntern(expression.AsSpan(startOfName, i - startOfName)); SinkWhitespace(expression, ref i); bool transformOrFunctionFound = true; @@ -251,10 +248,10 @@ internal static List GetReferencedItemExpressions(string subExpressions = new List(); } - // Create an expression capture that encompases the entire expression between the @( and the ) + // Create an expression capture that encompasses the entire expression between the @( and the ) // with the item name and any separator contained within it // and each transform expression contained within it (i.e. each ->XYZ) - ItemExpressionCapture expressionCapture = new ItemExpressionCapture(startPoint, endPoint - startPoint, expression.Substring(startPoint, endPoint - startPoint), itemName, separator, separatorStart, transformExpressions); + ItemExpressionCapture expressionCapture = new ItemExpressionCapture(startPoint, endPoint - startPoint, Microsoft.NET.StringTools.Strings.WeakIntern(expression.AsSpan(startPoint, endPoint - startPoint)), itemName, separator, separatorStart, transformExpressions); subExpressions.Add(expressionCapture); continue; @@ -601,7 +598,7 @@ private static ItemExpressionCapture SinkItemFunctionExpression(string expressio if (endFunctionArguments > startFunctionArguments) { - capture.FunctionArguments = expression.Substring(startFunctionArguments, endFunctionArguments - startFunctionArguments); + capture.FunctionArguments = Microsoft.NET.StringTools.Strings.WeakIntern(expression.AsSpan(startFunctionArguments, endFunctionArguments - startFunctionArguments)); } return capture;