From 3a5bd8cb89e6ced7dba344b4774a28b446e8f760 Mon Sep 17 00:00:00 2001 From: David Kean Date: Wed, 22 Jun 2022 16:23:19 +1000 Subject: [PATCH] Use ordinal comparisons Reduce the time it takes to find v1 and v2 export factory instances, this was costing 200ms in Startup.BuildingMEFCache perf test. --- .../Configuration/ExportMetadataViewInterfaceEmitProxy.cs | 2 +- src/Microsoft.VisualStudio.Composition/ExportFactory.cs | 8 ++++---- src/Microsoft.VisualStudio.Composition/ExportProvider.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.VisualStudio.Composition/Configuration/ExportMetadataViewInterfaceEmitProxy.cs b/src/Microsoft.VisualStudio.Composition/Configuration/ExportMetadataViewInterfaceEmitProxy.cs index 60502ad82..26034cc70 100644 --- a/src/Microsoft.VisualStudio.Composition/Configuration/ExportMetadataViewInterfaceEmitProxy.cs +++ b/src/Microsoft.VisualStudio.Composition/Configuration/ExportMetadataViewInterfaceEmitProxy.cs @@ -48,7 +48,7 @@ private static bool IsPropertyRelated(MemberInfo member) if (method != null) { return method.IsSpecialName - && method.Name.StartsWith("get_"); + && method.Name.StartsWith("get_", StringComparison.Ordinal); } return false; diff --git a/src/Microsoft.VisualStudio.Composition/ExportFactory.cs b/src/Microsoft.VisualStudio.Composition/ExportFactory.cs index 4ce212ef3..1edf96c54 100644 --- a/src/Microsoft.VisualStudio.Composition/ExportFactory.cs +++ b/src/Microsoft.VisualStudio.Composition/ExportFactory.cs @@ -27,7 +27,7 @@ internal static bool IsExportFactoryTypeV1(this Type type) if (type != null && type.GetTypeInfo().IsGenericType) { var typeDefinition = type.GetGenericTypeDefinition(); - if (typeDefinition.FullName?.StartsWith(ExportFactoryV1FullName) ?? false) + if (typeDefinition.FullName?.StartsWith(ExportFactoryV1FullName, StringComparison.Ordinal) ?? false) { return true; } @@ -43,7 +43,7 @@ internal static bool IsExportFactoryTypeV1(this TypeRef type) int arity = type.GenericTypeParameterCount + type.GenericTypeArguments.Length; if (arity > 0 && arity <= 2) { - if (type.FullName?.StartsWith(ExportFactoryV1FullName) ?? false) + if (type.FullName?.StartsWith(ExportFactoryV1FullName, StringComparison.Ordinal) ?? false) { return true; } @@ -58,7 +58,7 @@ internal static bool IsExportFactoryTypeV2(this Type type) if (type != null && type.GetTypeInfo().IsGenericType) { var typeDefinition = type.GetGenericTypeDefinition(); - if (typeDefinition.FullName?.StartsWith(ExportFactoryV2FullName) ?? false) + if (typeDefinition.FullName?.StartsWith(ExportFactoryV2FullName, StringComparison.Ordinal) ?? false) { return true; } @@ -74,7 +74,7 @@ internal static bool IsExportFactoryTypeV2(this TypeRef type) int arity = type.GenericTypeParameterCount + type.GenericTypeArguments.Length; if (arity > 0 && arity <= 2) { - if (type.FullName?.StartsWith(ExportFactoryV2FullName) ?? false) + if (type.FullName?.StartsWith(ExportFactoryV2FullName, StringComparison.Ordinal) ?? false) { return true; } diff --git a/src/Microsoft.VisualStudio.Composition/ExportProvider.cs b/src/Microsoft.VisualStudio.Composition/ExportProvider.cs index 3f290102c..592e62cf6 100644 --- a/src/Microsoft.VisualStudio.Composition/ExportProvider.cs +++ b/src/Microsoft.VisualStudio.Composition/ExportProvider.cs @@ -675,7 +675,7 @@ protected object GetStrongTypedMetadata(IReadOnlyDictionary met if (method != null) { // If the method came from a property, return the result of the property getter rather than return the delegate. - if (method.IsSpecialName && method.GetParameters().Length == 0 && method.Name.StartsWith("get_")) + if (method.IsSpecialName && method.GetParameters().Length == 0 && method.Name.StartsWith("get_", StringComparison.Ordinal)) { return method.Invoke(exportingPart, EmptyObjectArray); }