New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize Evaluate #5676
Optimize Evaluate #5676
Changes from 3 commits
8b59434
07a77e0
1e1939c
4b42650
a008a27
2d239b1
f476616
05272f8
57e230f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -738,11 +738,6 @@ internal static string ExpandMetadataLeaveEscaped(string expression, IMetadataTa | |
return expression; | ||
} | ||
|
||
if (expression.Length == 0) | ||
{ | ||
return expression; | ||
} | ||
|
||
ErrorUtilities.VerifyThrow(metadata != null, "Cannot expand metadata without providing metadata"); | ||
|
||
// PERF NOTE: Regex matching is expensive, so if the string doesn't contain any item metadata references, just bail | ||
|
@@ -1938,7 +1933,7 @@ private static class ItemExpander | |
internal static string ExpandItemVectorsIntoString<T>(Expander<P, I> expander, string expression, IItemProvider<T> items, ExpanderOptions options, IElementLocation elementLocation) | ||
where T : class, IItem | ||
{ | ||
if (((options & ExpanderOptions.ExpandItems) == 0) || (expression.Length == 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this condition was not helping? FWIW, the caller is not performing this check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The caller checks the length before it expands metadata and properties. If it's just a property or just metadata, and it happens to be empty, there could be an extra string before this, but I think that's the only case. Still valid, so I added it back. |
||
if ((options & ExpanderOptions.ExpandItems) == 0) | ||
{ | ||
return expression; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,7 +308,7 @@ public override string UnevaluatedValue | |
|
||
public override bool IsImported => Link.IsImported; | ||
|
||
internal override string EvaluatedValueEscapedIntenral => Link.EvaluatedIncludeEscaped; | ||
internal override string EvaluatedValueEscapedInternal => Link.EvaluatedIncludeEscaped; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this was in its own commit it'd be a lot easier to glance over, see that it's fine, and then ignore. |
||
} | ||
#endregion | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,20 +24,6 @@ static internal class EscapingUtilities | |
/// </summary> | ||
private static Dictionary<string, string> s_unescapedToEscapedStrings = new Dictionary<string, string>(StringComparer.Ordinal); | ||
|
||
/// <summary> | ||
/// Replaces all instances of %XX in the input string with the character represented | ||
/// by the hexadecimal number XX. | ||
/// </summary> | ||
/// <param name="escapedString">The string to unescape.</param> | ||
/// <returns>unescaped string</returns> | ||
internal static string UnescapeAll | ||
( | ||
string escapedString | ||
) | ||
{ | ||
return UnescapeAll(escapedString, out bool _); | ||
} | ||
|
||
private static bool IsHexDigit(char character) | ||
{ | ||
return ((character >= '0') && (character <= '9')) | ||
|
@@ -50,16 +36,10 @@ private static bool IsHexDigit(char character) | |
/// by the hexadecimal number XX. | ||
/// </summary> | ||
/// <param name="escapedString">The string to unescape.</param> | ||
/// <param name="escapingWasNecessary">Whether any replacements were made.</param> | ||
/// <param name="trim">If the string should be trimmed before being unescaped.</param> | ||
/// <returns>unescaped string</returns> | ||
internal static string UnescapeAll | ||
( | ||
string escapedString, | ||
out bool escapingWasNecessary | ||
) | ||
internal static string UnescapeAll(string escapedString, bool trim = false) | ||
{ | ||
escapingWasNecessary = false; | ||
|
||
// If the string doesn't contain anything, then by definition it doesn't | ||
// need unescaping. | ||
if (String.IsNullOrEmpty(escapedString)) | ||
|
@@ -79,6 +59,22 @@ internal static string UnescapeAll | |
StringBuilder unescapedString = StringBuilderCache.Acquire(escapedString.Length); | ||
|
||
int currentPosition = 0; | ||
int escapedStringLength = escapedString.Length; | ||
if (trim) | ||
{ | ||
while (currentPosition < escapedString.Length && Char.IsWhiteSpace(escapedString[currentPosition])) | ||
cdmihai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
currentPosition++; | ||
} | ||
if (currentPosition == escapedString.Length) | ||
{ | ||
return String.Empty; | ||
} | ||
while (Char.IsWhiteSpace(escapedString[escapedStringLength])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look correct. The last character is at index There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, line 85: (indexOfPercent <= (escapedStringLength - 3)) && instead of: (indexOfPercent <= (escapedString.Length - 3)) && There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, thanks! No reason to check that digits are hex if they're white space. |
||
{ | ||
escapedStringLength--; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. side-note: #5663 includes a Trim() implementation operating on spans which could potentially be used here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing to note is that if https://github.com/Therzok/BenchPlayground/blob/820035919d2a47506841041fe7caea799dc939ea/BenchPlayground/Benchmarks/runtime/SpanToString.md There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, the .NET Core implementation of |
||
} | ||
|
||
// Loop until there are no more percent signs in the input string. | ||
while (indexOfPercent != -1) | ||
|
@@ -106,8 +102,6 @@ internal static string UnescapeAll | |
// Advance the current pointer to reflect the fact that the destination string | ||
// is up to date with everything up to and including this escape code we just found. | ||
currentPosition = indexOfPercent + 3; | ||
|
||
escapingWasNecessary = true; | ||
} | ||
|
||
// Find the next percent sign. | ||
|
@@ -116,7 +110,7 @@ internal static string UnescapeAll | |
|
||
// Okay, there are no more percent signs in the input string, so just copy the remaining | ||
// characters into the destination. | ||
unescapedString.Append(escapedString, currentPosition, escapedString.Length - currentPosition); | ||
unescapedString.Append(escapedString, currentPosition, escapedStringLength - currentPosition); | ||
|
||
return StringBuilderCache.GetStringAndRelease(unescapedString); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,20 @@ internal static string EnsureNoTrailingSlash(string path) | |
return path; | ||
} | ||
|
||
/// <summary> | ||
/// Ensures the path does not have a leading or trailing slash. | ||
/// </summary> | ||
internal static string EnsureNoLeadingOrTrailingSlash(string path) | ||
{ | ||
if (String.IsNullOrEmpty(path)) | ||
{ | ||
return path; | ||
} | ||
int start = IsSlash(path[0]) ? 1 : 0; | ||
int end = IsSlash(path[path.Length - 1]) ? 1 : 0; | ||
return path.Substring(start, path.Length - start - end); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would blow up on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thanks! |
||
} | ||
|
||
/// <summary> | ||
/// Indicates if the given file-spec ends with a slash. | ||
/// </summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can this be removed?