diff --git a/src/Microsoft.TestPlatform.Filter.Source/Condition.cs b/src/Microsoft.TestPlatform.Filter.Source/Condition.cs index 12b0556273..ad5ddb37eb 100644 --- a/src/Microsoft.TestPlatform.Filter.Source/Condition.cs +++ b/src/Microsoft.TestPlatform.Filter.Source/Condition.cs @@ -157,8 +157,32 @@ internal bool Evaluate(Func propertyValueProvider) #if IS_VSTEST_REPO ValidateArg.NotNull(propertyValueProvider, nameof(propertyValueProvider)); #endif - var multiValue = GetPropertyValue(propertyValueProvider); - var result = Operation switch + var propertyValue = propertyValueProvider(Name); + + // Fast path: single string value (most common case for FullyQualifiedName, DisplayName, etc.) + // Avoids allocating a string[1] wrapper that the general multi-value path would create. + if (propertyValue is string singleValue) + { + return Operation switch + { + Operation.Equal => string.Equals(singleValue, Value, StringComparison.OrdinalIgnoreCase), + Operation.NotEqual => !string.Equals(singleValue, Value, StringComparison.OrdinalIgnoreCase), + Operation.Contains => singleValue.IndexOf(Value, StringComparison.OrdinalIgnoreCase) != -1, + Operation.NotContains => singleValue.IndexOf(Value, StringComparison.OrdinalIgnoreCase) == -1, + _ => false, + }; + } + + // Null, string[], or other types: use multi-value evaluation. + // Other types are coerced via ToString() for backward compatibility. + string[]? multiValue = propertyValue switch + { + null => null, + string[] arr => arr, + _ => new[] { propertyValue.ToString()! }, + }; + + return Operation switch { // if any value in multi-valued property matches 'this.Value', for Equal to evaluate true. Operation.Equal => EvaluateEqualOperation(multiValue), @@ -170,8 +194,6 @@ internal bool Evaluate(Func propertyValueProvider) Operation.NotContains => !EvaluateContainsOperation(multiValue), _ => false, }; - - return result; } /// @@ -292,25 +314,6 @@ private static Operation GetOperator(string operationString) }; } - /// - /// Returns property value for Property using propertValueProvider. - /// - private string[]? GetPropertyValue(Func propertyValueProvider) - { - var propertyValue = propertyValueProvider(Name); - if (null != propertyValue) - { - if (propertyValue is not string[] multiValue) - { - multiValue = new string[1]; - multiValue[0] = propertyValue.ToString()!; - } - return multiValue; - } - - return null; - } - internal static IEnumerable TokenizeFilterConditionString(string str) { return str == null ? throw new ArgumentNullException(nameof(str)) : TokenizeFilterConditionStringWorker(str);