-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Eval cond perf #6859
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
Eval cond perf #6859
Changes from 5 commits
e02b3d9
64354ff
762ac1d
f9456c4
16a30b3
6e4c0d4
2aac6e2
0134385
625fd3f
62760c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |||||
|
|
||||||
| using System; | ||||||
| using System.Diagnostics; | ||||||
|
|
||||||
| using Microsoft.Build.Shared; | ||||||
|
|
||||||
| namespace Microsoft.Build.Evaluation | ||||||
|
|
@@ -85,6 +84,37 @@ internal override bool CanVersionEvaluate(ConditionEvaluator.IConditionEvaluatio | |||||
| return Version.TryParse(GetExpandedValue(state), out _); | ||||||
| } | ||||||
|
|
||||||
| internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result) | ||||||
| { | ||||||
| return ConversionUtilities.TryConvertStringToBool(GetExpandedValue(state), out result); | ||||||
| } | ||||||
|
|
||||||
| internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result) | ||||||
| { | ||||||
| if (ShouldBeTreatedAsVisualStudioVersion(state)) | ||||||
|
Member
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. Should
Member
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. Or alternately should we entirely remove the non- |
||||||
| { | ||||||
| result = ConversionUtilities.ConvertDecimalOrHexToDouble(MSBuildConstants.CurrentVisualStudioVersion); | ||||||
| return true; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| return ConversionUtilities.TryConvertDecimalOrHexToDouble(GetExpandedValue(state), out result); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result) | ||||||
| { | ||||||
| if (ShouldBeTreatedAsVisualStudioVersion(state)) | ||||||
| { | ||||||
| result = Version.Parse(MSBuildConstants.CurrentVisualStudioVersion); | ||||||
| return true; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| return Version.TryParse(GetExpandedValue(state), out result); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Returns true if this node evaluates to an empty string, | ||||||
| /// otherwise false. | ||||||
|
|
@@ -98,6 +128,25 @@ internal override bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationS | |||||
| { | ||||||
| if (_expandable) | ||||||
| { | ||||||
| switch (_value.Length) | ||||||
| { | ||||||
| case 0: | ||||||
| _cachedExpandedValue = String.Empty; | ||||||
| return true; | ||||||
| // If the length is 1 or 2, it can't possibly be a property, item, or metadata, and it isn't empty. | ||||||
| case 1: | ||||||
| case 2: | ||||||
| _cachedExpandedValue = _value; | ||||||
| return false; | ||||||
| default: | ||||||
| if (_value[1] != '(' || _value[_value.Length - 1] != ')' || (_value[0] != '$' && _value[0] != '%' && _value[0] != '@')) | ||||||
|
||||||
| if (_value[1] != '(' || _value[_value.Length - 1] != ')' || (_value[0] != '$' && _value[0] != '%' && _value[0] != '@')) | |
| if (_value[1] != '(' || (_value[0] != '$' && _value[0] != '%' && _value[0] != '@') || _value[_value.Length - 1] != ')') |
For a long _value the CPU might have to fault in the memory for the end of the string when accessing it, but we're guaranteed that the second character of the string was loaded at the same time as the first, so this can avoid cache misses.
Our strings are usually short so this probably won't generally matter, and even if it did it probably wouldn't matter much. But I know this kind of thing is up your alley so I figured I'd mention it :)
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,12 +110,14 @@ internal static List<ItemExpressionCapture> GetReferencedItemExpressions(string | |
| { | ||
| List<ItemExpressionCapture> subExpressions = null; | ||
|
|
||
| if (expression.IndexOf('@') < 0) | ||
| int startInd = expression.IndexOf('@', start, end - start); | ||
|
||
|
|
||
| if (startInd < 0) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| for (int i = start; i < end; i++) | ||
| for (int i = startInd; i < end; i++) | ||
| { | ||
| int restartPoint; | ||
| int startPoint; | ||
|
|
||
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.
Nice comment 👍🏻