From 4f96d00a86e7e547f79d78610d4b4b71202b07e6 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 28 Jul 2020 02:03:10 +0100 Subject: [PATCH 1/4] Use char.{Last}IndexOf --- .../Internal/MarkupCompiler/MarkupCompiler.cs | 14 ++++++------ .../MarkupCompiler/ParserExtension.cs | 4 ++-- .../MS/Internal/Tasks/CompilerWrapper.cs | 4 ++-- .../Build/Tasks/Windows/MarkupCompilePass1.cs | 2 +- .../Build/Tasks/Windows/MarkupCompilePass2.cs | 2 +- .../Windows/Input/Command/KeyGesture.cs | 6 ++--- .../System/Windows/Input/CursorConverter.cs | 2 +- .../WindowsRuntime/Generated/WinRT.cs | 2 +- .../Controls/VirtualizingStackPanel.cs | 2 +- .../Windows/Documents/RtfToXamlReader.cs | 4 ++-- .../Windows/Documents/XamlToRtfWriter.cs | 2 +- .../Windows/Input/Command/CommandConverter.cs | 2 +- .../System/Windows/Markup/BamlMapTable.cs | 2 +- .../System/Windows/Markup/BamlReader.cs | 22 +++++++++---------- .../Windows/Markup/Primitives/MarkupWriter.cs | 4 ++-- .../System/Xaml/MS/Impl/KnownStrings.cs | 8 +++++++ .../Xaml/Schema/ClrNamespaceUriParser.cs | 6 ++--- 17 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs index 8adf6cf0664..9638cd29f66 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs @@ -487,7 +487,7 @@ private void Initialize(FileUnit sourceFile) } } - int pathEndIndex = SourceFileInfo.RelativeSourceFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal); + int pathEndIndex = SourceFileInfo.RelativeSourceFilePath.LastIndexOf(Path.DirectorySeparatorChar); string targetPath = TargetPath + SourceFileInfo.RelativeSourceFilePath.Substring(0, pathEndIndex + 1); // Create if not already exists @@ -711,7 +711,7 @@ private SourceFileInfo OnSourceFileResolve(FileUnit file) if (sourceFileInfo.IsXamlFile) { - int fileExtIndex = file.Path.LastIndexOf(DOT, StringComparison.Ordinal); + int fileExtIndex = file.Path.LastIndexOf(DOTCHAR); sourceFileInfo.RelativeSourceFilePath = file.Path.Substring(0, fileExtIndex); } @@ -1415,7 +1415,7 @@ private string GetFullClassName(string ns, string className) internal void ValidateFullSubClassName(ref string subClassFullName) { bool isValid = false; - int index = subClassFullName.LastIndexOf(DOT, StringComparison.Ordinal); + int index = subClassFullName.LastIndexOf(DOTCHAR); if (index > 0) { @@ -1444,7 +1444,7 @@ private bool CrackClassName(ref string className, out string ns) if (className.Length > 0) { // Split the Namespace - int index = className.LastIndexOf(DOT, StringComparison.Ordinal); + int index = className.LastIndexOf(DOTCHAR); if (index > 0) { @@ -2273,7 +2273,7 @@ private static CodeTypeReference GenerateConstructedTypeReference(Type t, string // NOTE: Remove when CodeDom is fixed to understand mangled generic names. genericName = t.FullName; - int bang = genericName.IndexOf(GENERIC_DELIMITER, StringComparison.Ordinal); + int bang = genericName.IndexOf(GENERIC_DELIMITER); if (bang > 0) { genericName = genericName.Substring(0, bang); @@ -2316,7 +2316,7 @@ private static CodeTypeReference GenerateConstructedTypeReference(Type t, string // NOTE: Remove when CodeDom is fixed to understand mangled generic names. string genericName = t.Namespace + DOT + t.Name; - int bang = genericName.IndexOf(GENERIC_DELIMITER, StringComparison.Ordinal); + int bang = genericName.IndexOf(GENERIC_DELIMITER); if (bang > 0) { genericName = genericName.Substring(0, bang); @@ -3492,7 +3492,7 @@ internal string SubClass private const string ANONYMOUS_ENTRYCLASS_PREFIX = "Generated"; private const string DEFINITION_PREFIX = "x"; private const char COMMA = ','; - private const string GENERIC_DELIMITER = "`"; + private const char GENERIC_DELIMITER = '`'; internal const char DOTCHAR = '.'; internal const string DOT = "."; internal const string CODETAG = "Code"; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs index f854f1b53ba..284a4e2209d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs @@ -839,7 +839,7 @@ public override void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode { if (_class == MarkupCompiler.DOT) { - int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOT, StringComparison.Ordinal); + int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOTCHAR); ThrowException(SRID.InvalidClassName, MarkupCompiler.DefinitionNSPrefix, CLASS, @@ -869,7 +869,7 @@ public override void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode { if (_subClass == MarkupCompiler.DOT) { - int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOT, StringComparison.Ordinal); + int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOTCHAR); ThrowException(SRID.InvalidClassName, MarkupCompiler.DefinitionNSPrefix, SUBCLASS, diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs index d47c9af6ff0..0123a781b0b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs @@ -358,7 +358,7 @@ private void OnSourceFileResolve(Object sender, SourceFileResolveEventArgs e) // // For Xaml Source file, we need to remove the .xaml extension part. // - int fileExtIndex = newRelativeFilePath.LastIndexOf(MarkupCompiler.DOT, StringComparison.Ordinal); + int fileExtIndex = newRelativeFilePath.LastIndexOf(MarkupCompiler.DOTCHAR); newRelativeFilePath = newRelativeFilePath.Substring(0, fileExtIndex); } @@ -408,7 +408,7 @@ private string GetResolvedFilePath(string filePath, ref string newSourceDir) // and put the deepest directory that file is in as the new // SourceDir. // - int pathEndIndex = fullFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal); + int pathEndIndex = fullFilePath.LastIndexOf(Path.DirectorySeparatorChar); newSourceDir = fullFilePath.Substring(0, pathEndIndex + 1); newRelativeFilePath = fullFilePath.Substring(pathEndIndex + 1); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass1.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass1.cs index 2aa187e9f48..ac1869ca34b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass1.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass1.cs @@ -1080,7 +1080,7 @@ private string GetResolvedFilePath(string filePath, ref string newSourceDir) // and put the deepest directory that file is in as the new // SourceDir. // - int pathEndIndex = fullFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal); + int pathEndIndex = fullFilePath.LastIndexOf(Path.DirectorySeparatorChar); newSourceDir = fullFilePath.Substring(0, pathEndIndex + 1); newRelativeFilePath = TaskHelper.GetRootRelativePath(newSourceDir, fullFilePath); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass2.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass2.cs index b00d05886dd..cebc9788376 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass2.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MarkupCompilePass2.cs @@ -545,7 +545,7 @@ private string GetResolvedFilePath(string filePath, ref string newSourceDir) // and put the deepest directory that file is in as the new // SourceDir. // - int pathEndIndex = fullFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal); + int pathEndIndex = fullFilePath.LastIndexOf(Path.DirectorySeparatorChar); newSourceDir = fullFilePath.Substring(0, pathEndIndex + 1); newRelativeFilePath = TaskHelper.GetRootRelativePath(newSourceDir, fullFilePath); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/KeyGesture.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/KeyGesture.cs index 69d3bf8518c..6610e1b5287 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/KeyGesture.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/KeyGesture.cs @@ -253,7 +253,7 @@ internal static void AddGesturesFromResourceStrings(string keyGestures, string d string keyDisplayString; // break apart first gesture from the rest - int index = keyGestures.IndexOf(MULTIPLEGESTURE_DELIMITER, StringComparison.Ordinal); + int index = keyGestures.IndexOf(MULTIPLEGESTURE_DELIMITER); if (index >= 0) { // multiple gestures exist keyGestureToken = keyGestures.Substring(0, index); @@ -266,7 +266,7 @@ internal static void AddGesturesFromResourceStrings(string keyGestures, string d } // similarly, break apart first display string from the rest - index = displayStrings.IndexOf(MULTIPLEGESTURE_DELIMITER, StringComparison.Ordinal); + index = displayStrings.IndexOf(MULTIPLEGESTURE_DELIMITER); if (index >= 0) { // multiple display strings exist keyDisplayString = displayStrings.Substring(0, index); @@ -310,7 +310,7 @@ internal static KeyGesture CreateFromResourceStrings(string keyGestureToken, str private ModifierKeys _modifiers = ModifierKeys.None; private Key _key = Key.None; private string _displayString; - private const string MULTIPLEGESTURE_DELIMITER = ";"; + private const char MULTIPLEGESTURE_DELIMITER = ';'; private static TypeConverter _keyGestureConverter = new KeyGestureConverter(); //private static bool _classRegistered = false; #endregion Private Fields diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/CursorConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/CursorConverter.cs index d00bd087cba..336cbd539bc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/CursorConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/CursorConverter.cs @@ -113,7 +113,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (text != String.Empty) { - if (text.LastIndexOf(".", StringComparison.Ordinal) == -1) + if (text.LastIndexOf('.') == -1) { CursorType ct = (CursorType)Enum.Parse(typeof(CursorType), text); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs index 713cdff4773..7d74d32f710 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs @@ -256,7 +256,7 @@ public BaseActivationFactory(string typeNamespace, string typeFullName) } catch (Exception) { } - var lastSegment = moduleName.LastIndexOf("."); + var lastSegment = moduleName.LastIndexOf('.'); if (lastSegment <= 0) { Marshal.ThrowExceptionForHR(hr); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs index 269b64e1cf5..5a9aca1654f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs @@ -12378,7 +12378,7 @@ private static TraceList AddToMap(ItemsControl target) } if (filename != "none" && s_seqno > 1) { - int dotIndex = filename.LastIndexOf(".", StringComparison.Ordinal); + int dotIndex = filename.LastIndexOf('.'); if (dotIndex < 0) dotIndex = filename.Length; filename = filename.Substring(0, dotIndex) + s_seqno.ToString() + diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs index 2b000132d13..99af3a0f74d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs @@ -8238,7 +8238,7 @@ internal void ProcessField() // is very low. Now we replace image with the included picture uri to get // the image directly from the specified Uri. int uriSourceIndex = dnImage.Xaml.IndexOf("UriSource=", StringComparison.Ordinal); - int uriSourceEndIndex = dnImage.Xaml.IndexOf("\"", uriSourceIndex + 11, StringComparison.Ordinal); + int uriSourceEndIndex = dnImage.Xaml.IndexOf('\"', uriSourceIndex + 11); string imageXaml = dnImage.Xaml.Substring(0, uriSourceIndex); imageXaml += "UriSource=\"" + pictureUri + "\""; @@ -8410,7 +8410,7 @@ private string GetIncludePictureUri(string instructionName) { pictureUri = instructionName.Substring(uriIndex, instructionName.Length - uriIndex - 1); - int pictureUriEndIndex = pictureUri.IndexOf("\"", StringComparison.OrdinalIgnoreCase); + int pictureUriEndIndex = pictureUri.IndexOf('\"'); if (pictureUriEndIndex != -1) { pictureUri = pictureUri.Substring(0, pictureUriEndIndex); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs index f1238c48fa2..5bf5bb768e1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs @@ -2231,7 +2231,7 @@ private RtfImageFormat GetImageFormatFromImageSourceName(string imageName) { RtfImageFormat imageFormat = RtfImageFormat.Unknown; - int extensionIndex = imageName.LastIndexOf(".", StringComparison.OrdinalIgnoreCase); + int extensionIndex = imageName.LastIndexOf('.'); if (extensionIndex >= 0) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/Command/CommandConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/Command/CommandConverter.cs index 4752bb5de81..13ec706ac17 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/Command/CommandConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/Command/CommandConverter.cs @@ -235,7 +235,7 @@ private void ParseUri( string source, out string typeName, out string localName localName = ((string)source).Trim(); // split CommandName from its TypeName (e.g. ScrollViewer.PageDownCommand to Scrollviewerand PageDownCommand) - int Offset = localName.LastIndexOf(".", StringComparison.Ordinal); + int Offset = localName.LastIndexOf('.'); if (Offset >= 0) { typeName = localName.Substring(0, Offset); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs index 73538580e8a..dfac61ecc78 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs @@ -1170,7 +1170,7 @@ internal bool GetTypeInfoId( string typeFullName, out short typeId) { - int dotIndex = typeFullName.LastIndexOf(".", StringComparison.Ordinal); + int dotIndex = typeFullName.LastIndexOf('.'); string typeShortName; string typeClrNamespace; if (dotIndex >= 0) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs index fdb9daef0bf..f1c67a32547 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs @@ -392,7 +392,7 @@ public bool MoveToNextProperty() { _name = info.Name; _localName = info.LocalName; - int index = info.Name.LastIndexOf(".", StringComparison.Ordinal); + int index = info.Name.LastIndexOf('.'); if (index > 0) { _ownerTypeName = info.Name.Substring(0, index); @@ -439,7 +439,7 @@ public bool MoveToNextProperty() _connectionId = 0; _prefix = string.Empty; _name = cpInfo.Name; - int index = cpInfo.Name.LastIndexOf(".", StringComparison.Ordinal); + int index = cpInfo.Name.LastIndexOf('.'); if (index > 0) { _ownerTypeName = cpInfo.Name.Substring(0, index); @@ -1305,7 +1305,7 @@ private void ProcessDeferKey() } BamlTypeInfoRecord typeInfo = MapTable.GetTypeInfoFromId(typeKeyRecord.TypeId); string typeName = typeInfo.TypeFullName; - typeName = typeName.Substring(typeName.LastIndexOf(".", StringComparison.Ordinal) + 1); + typeName = typeName.Substring(typeName.LastIndexOf('.') + 1); string assemblyName; string prefix; string xmlNamespace; @@ -1425,7 +1425,7 @@ private BamlKeyInfo ProcessKeyTree() // a x:Key attribute. BamlTypeInfoRecord typeInfo = MapTable.GetTypeInfoFromId(keyStartRecord.TypeId); string markupString = typeInfo.TypeFullName; - markupString = markupString.Substring(markupString.LastIndexOf(".", StringComparison.Ordinal) + 1); + markupString = markupString.Substring(markupString.LastIndexOf('.') + 1); string assemblyName; string prefix; string xmlNamespace; @@ -1552,7 +1552,7 @@ private BamlKeyInfo ProcessKeyTree() BamlElementStartRecord elementStartRecord = _currentBamlRecord as BamlElementStartRecord; BamlTypeInfoRecord elementTypeInfo = MapTable.GetTypeInfoFromId(elementStartRecord.TypeId); string typename = elementTypeInfo.TypeFullName; - typename = typename.Substring(typename.LastIndexOf(".", StringComparison.Ordinal) + 1); + typename = typename.Substring(typename.LastIndexOf('.') + 1); GetAssemblyAndPrefixAndXmlns(elementTypeInfo, out assemblyName, out prefix, out xmlNamespace); if (prefix != string.Empty) { @@ -1964,7 +1964,7 @@ private void ReadElementStartRecord() NodeTypeInternal = BamlNodeType.StartElement; _name = typeInfo.TypeFullName; - _localName = _name.Substring(_name.LastIndexOf(".", StringComparison.Ordinal) + 1); + _localName = _name.Substring(_name.LastIndexOf('.') + 1); _ownerTypeName = string.Empty; _clrNamespace = typeInfo.ClrNamespace; GetAssemblyAndPrefixAndXmlns(typeInfo, out _assemblyName, out _prefix, out _xmlNamespace); @@ -2081,7 +2081,7 @@ private void ReadPropertyComplexStartRecord() // Set instance variables to node info extracted from record. NodeTypeInternal = BamlNodeType.StartComplexProperty; _localName = nodeInfo.LocalName; - int index = nodeInfo.Name.LastIndexOf(".", StringComparison.Ordinal); + int index = nodeInfo.Name.LastIndexOf('.'); if (index > 0) { _ownerTypeName = nodeInfo.Name.Substring(0, index); @@ -2152,7 +2152,7 @@ private void ReadPropertyComplexEndRecord() NodeTypeInternal = BamlNodeType.EndComplexProperty; _name = nodeInfo.Name; _localName = nodeInfo.LocalName; - int index = nodeInfo.Name.LastIndexOf(".", StringComparison.Ordinal); + int index = nodeInfo.Name.LastIndexOf('.'); if (index > 0) { _ownerTypeName = nodeInfo.Name.Substring(0, index); @@ -2409,7 +2409,7 @@ private string GetTemplateBindingExtensionValueString(short memberId) string valueAssemblyName; GetAssemblyAndPrefixAndXmlns(valueTypeInfo, out valueAssemblyName, out valuePrefix, out valueXmlNamespace); typeName = valueTypeInfo.TypeFullName; - typeName = typeName.Substring(typeName.LastIndexOf(".", StringComparison.Ordinal) + 1); + typeName = typeName.Substring(typeName.LastIndexOf('.') + 1); propName = attrInfo.Name; } @@ -2484,7 +2484,7 @@ private string GetStaticExtensionValueString(short memberId) string valueAssemblyName; GetAssemblyAndPrefixAndXmlns(valueTypeInfo, out valueAssemblyName, out valuePrefix, out valueXmlNamespace); typeName = valueTypeInfo.TypeFullName; - typeName = typeName.Substring(typeName.LastIndexOf(".", StringComparison.Ordinal) + 1); + typeName = typeName.Substring(typeName.LastIndexOf('.') + 1); propName = attrInfo.Name; } @@ -2598,7 +2598,7 @@ private string GetTypeValueString(short typeId) string valueAssemblyName; GetAssemblyAndPrefixAndXmlns(valueTypeInfo, out valueAssemblyName, out valuePrefix, out valueXmlNamespace); string typeName = valueTypeInfo.TypeFullName; - typeName = typeName.Substring(typeName.LastIndexOf(".", StringComparison.Ordinal) + 1); + typeName = typeName.Substring(typeName.LastIndexOf('.') + 1); if (valuePrefix == string.Empty) { valueString += typeName; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs index 5c5e121d4d6..16be0678f53 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs @@ -841,7 +841,7 @@ private void WriteItem(MarkupObject item, Scope scope) writtenAttributes[property.Name] = property.Name; _writer.WriteStartElement(prefix, item.ObjectType.Name + "." + property.PropertyDescriptor.Name, uri); - if (property.IsComposite || property.StringValue.IndexOf("{", StringComparison.Ordinal) == 0) + if (property.IsComposite || property.StringValue.IndexOf('{') == 0) { foreach (MarkupObject subItem in property.Items) { @@ -1649,7 +1649,7 @@ public static string GetDefaultPrefixFor(string uri) result = "assembly"; if (uri.StartsWith(clrUriPrefix, StringComparison.Ordinal)) { - string ns = uri.Substring(clrUriPrefix.Length, uri.IndexOf(";", StringComparison.Ordinal) - clrUriPrefix.Length); + string ns = uri.Substring(clrUriPrefix.Length, uri.IndexOf(';') - clrUriPrefix.Length); StringBuilder r = new StringBuilder(); for (int i = 0; i < ns.Length; i++) { diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs index d4057582c21..04afe4a17b4 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs @@ -62,6 +62,14 @@ public static bool Eq(string a, string b) return string.Equals(a, b, StringComparison.Ordinal); } + /// + /// Standard String Index search operation. + /// + public static int IndexOf(string src, char value) + { + return src.IndexOf(value); + } + /// /// Standard String Index search operation. /// diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs index 2f32904184e..b5e1994cf91 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs @@ -23,7 +23,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass // xmlns:bar="clr-namespace:MyAppsNs" // xmlns:spam="clr-namespace:MyAppsNs;assembly=" - int colonIdx = KS.IndexOf(uriInput, ":"); + int colonIdx = KS.IndexOf(uriInput, ':'); if (colonIdx == -1) { return false; @@ -36,7 +36,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass } int clrNsStartIdx = colonIdx + 1; - int semicolonIdx = KS.IndexOf(uriInput, ";"); + int semicolonIdx = KS.IndexOf(uriInput, ';'); if (semicolonIdx == -1) { clrNs = uriInput.Substring(clrNsStartIdx); @@ -50,7 +50,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass } int assemblyKeywordStartIdx = semicolonIdx+1; - int equalIdx = KS.IndexOf(uriInput, "="); + int equalIdx = KS.IndexOf(uriInput, '='); if (equalIdx == -1) { return false; From aca34538d67260a52ac4395a831040231d4d26ba Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Wed, 13 Jan 2021 13:25:26 -0500 Subject: [PATCH 2/4] Use char overload in System.Xaml --- .../Windows/Markup/DateTimeValueSerializer.cs | 2 +- .../System/Xaml/InfosetObjects/XamlObjectWriter.cs | 6 +++--- .../System/Xaml/MS/Impl/KnownStrings.cs | 8 ++++++++ .../System.Xaml/System/Xaml/Parser/MeScanner.cs | 4 ++-- .../src/System.Xaml/System/Xaml/Parser/XamlName.cs | 2 +- .../System/Xaml/Schema/ClrNamespaceUriParser.cs | 6 +++--- .../System/Xaml/XamlMarkupExtensionWriter.cs | 14 +++++++------- .../src/System.Xaml/System/Xaml/XamlType.cs | 10 +++++----- .../src/System.Xaml/System/Xaml/XamlTypeName.cs | 10 +++++----- .../src/System.Xaml/System/Xaml/XamlXmlWriter.cs | 4 ++-- 10 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/DateTimeValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/DateTimeValueSerializer.cs index 82b8ff36d25..0e2e0a63147 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/DateTimeValueSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/DateTimeValueSerializer.cs @@ -159,7 +159,7 @@ public override string ConvertToString(object value, IValueSerializerContext con // included in the output formulation -- UTC gets written out with a "Z", // and Local gets written out with e.g. "-08:00" for Pacific Standard Time. - formatString.Append("K"); + formatString.Append('K'); // We've finally got our format string built, we can create the string. diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs index fbc37096a45..e8d60d9ec6a 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs @@ -1996,7 +1996,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx) if (value is NameFixupToken && parentProperty != XamlLanguage.Items) { NameFixupToken token = value as NameFixupToken; - string names = String.Join(",", token.NeededNames.ToArray()); + string names = String.Join(',', token.NeededNames.ToArray()); string msg = SR.Get(SRID.ForwardRefDirectives, names); throw ctx.WithLineInfo(new XamlObjectWriterException(msg)); } @@ -2033,7 +2033,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx) // Only the key directive may be assigned a reference. if (parentProperty != XamlLanguage.Key) { - string names = String.Join(",", token.NeededNames.ToArray()); + string names = String.Join(',', token.NeededNames.ToArray()); string msg = SR.Get(SRID.ForwardRefDirectives, names); throw ctx.WithLineInfo(new XamlObjectWriterException(msg)); } @@ -2086,7 +2086,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx) if (parentProperty != XamlLanguage.Key) { NameFixupToken token = (NameFixupToken)value; - string names = String.Join(",", token.NeededNames.ToArray()); + string names = String.Join(',', token.NeededNames.ToArray()); string msg = SR.Get(SRID.ForwardRefDirectives, names); throw ctx.WithLineInfo(new XamlObjectWriterException(msg)); } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs index d4057582c21..c3d6341f5ac 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs @@ -70,6 +70,14 @@ public static int IndexOf(string src, string chars) return src.IndexOf(chars, StringComparison.Ordinal); } + /// + /// Standard String Index search operation. + /// + public static int IndexOf(string src, char ch) + { + return src.IndexOf(ch, StringComparison.Ordinal); + } + public static bool EndsWith(string src, string target) { return src.EndsWith(target, StringComparison.Ordinal); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs index 69fad866494..e9ce52bf162 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs @@ -243,7 +243,7 @@ private static string RemoveEscapes(string value) value = value.Substring(2); } - if (!value.Contains("\\")) + if (!value.Contains(Backslash)) { return value; } @@ -352,7 +352,7 @@ private string ReadString() // handle escaping and quoting first. if(escaped) { - sb.Append('\\'); + sb.Append(Backslash); sb.Append(ch); escaped = false; } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs index d7a99f1b392..54e873c0771 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs @@ -37,7 +37,7 @@ public XamlName(string prefix, string name) public static bool ContainsDot(string name) { - return name.Contains("."); + return name.Contains(Dot); } public static bool IsValidXamlName(string name) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs index 2f32904184e..b5e1994cf91 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrNamespaceUriParser.cs @@ -23,7 +23,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass // xmlns:bar="clr-namespace:MyAppsNs" // xmlns:spam="clr-namespace:MyAppsNs;assembly=" - int colonIdx = KS.IndexOf(uriInput, ":"); + int colonIdx = KS.IndexOf(uriInput, ':'); if (colonIdx == -1) { return false; @@ -36,7 +36,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass } int clrNsStartIdx = colonIdx + 1; - int semicolonIdx = KS.IndexOf(uriInput, ";"); + int semicolonIdx = KS.IndexOf(uriInput, ';'); if (semicolonIdx == -1) { clrNs = uriInput.Substring(clrNsStartIdx); @@ -50,7 +50,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass } int assemblyKeywordStartIdx = semicolonIdx+1; - int equalIdx = KS.IndexOf(uriInput, "="); + int equalIdx = KS.IndexOf(uriInput, '='); if (equalIdx == -1) { return false; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs index 4ac6f499acb..6908135d235 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs @@ -260,12 +260,12 @@ protected static string FormatStringInCorrectSyntax(string s) if (s[i] == '\\' || s[i] == '"') { - sb.Append("\\"); + sb.Append('\\'); } sb.Append(s[i]); } - sb.Append("\""); + sb.Append('\"'); return sb.ToString(); } @@ -274,7 +274,7 @@ protected void WritePrefix(XamlMarkupExtensionWriter writer, string prefix) if (!string.IsNullOrEmpty(prefix)) { writer.sb.Append(prefix); - writer.sb.Append(":"); + writer.sb.Append(':'); } } @@ -308,7 +308,7 @@ public override void WriteStartObject(XamlMarkupExtensionWriter writer, XamlType string prefix = writer.LookupPrefix(type); - writer.sb.Append("{"); + writer.sb.Append('{'); WritePrefix(writer, prefix); writer.sb.Append(XamlXmlWriter.GetTypeName(type)); @@ -342,7 +342,7 @@ public override void WriteEndObject(XamlMarkupExtensionWriter writer) throw new InvalidOperationException(SR.Get(SRID.XamlMarkupExtensionWriterInputInvalid)); } - writer.sb.Append("}"); + writer.sb.Append('}'); if (writer.nodes.Count == 0) { @@ -419,7 +419,7 @@ protected void WriteNonPositionalParameterMember(XamlMarkupExtensionWriter write writer.sb.Append(property.Name); } - writer.sb.Append("="); + writer.sb.Append('='); writer.currentState = InMember.State; } @@ -576,7 +576,7 @@ public override void WriteStartObject(XamlMarkupExtensionWriter writer, XamlType } string prefix = writer.LookupPrefix(type); - writer.sb.Append("{"); + writer.sb.Append('{'); WritePrefix(writer, prefix); writer.sb.Append(XamlXmlWriter.GetTypeName(type)); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs index 1a31c4909e3..6b8f735eb4e 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs @@ -1361,19 +1361,19 @@ private void AppendTypeName(StringBuilder sb, bool forceNsInitialization) } if (!string.IsNullOrEmpty(ns)) { - sb.Append("{"); + sb.Append('{'); sb.Append(PreferredXamlNamespace); - sb.Append("}"); + sb.Append('}'); } else if (UnderlyingTypeInternal.Value != null) { sb.Append(UnderlyingTypeInternal.Value.Namespace); - sb.Append("."); + sb.Append('.'); } sb.Append(Name); if (IsGeneric) { - sb.Append("("); + sb.Append('('); for (int i = 0; i < TypeArguments.Count; i++) { TypeArguments[i].AppendTypeName(sb, forceNsInitialization); @@ -1382,7 +1382,7 @@ private void AppendTypeName(StringBuilder sb, bool forceNsInitialization) sb.Append(", "); } } - sb.Append(")"); + sb.Append(')'); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs index 067609bae6b..3aa8be55c17 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs @@ -242,9 +242,9 @@ internal void ConvertToStringInternal(StringBuilder result, Func } if (prefixGenerator == null) { - result.Append("{"); + result.Append('{'); result.Append(Namespace); - result.Append("}"); + result.Append('}'); } else { @@ -256,7 +256,7 @@ internal void ConvertToStringInternal(StringBuilder result, Func if (prefix.Length != 0) { result.Append(prefix); - result.Append(":"); + result.Append(':'); } } if (HasTypeArgs) @@ -266,9 +266,9 @@ internal void ConvertToStringInternal(StringBuilder result, Func string name = GenericTypeNameScanner.StripSubscript(Name, out subscript); result.Append(name); - result.Append("("); + result.Append('('); ConvertListToStringInternal(result, TypeArguments, prefixGenerator); - result.Append(")"); + result.Append(')'); result.Append(subscript); } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs index ca76a14b415..8ce5a39f1cf 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs @@ -655,7 +655,7 @@ void ConvertXamlTypeToStringHelper(XamlType type, StringBuilder builder) if (type.TypeArguments != null) { bool added = false; - builder.Append("("); + builder.Append('('); foreach (XamlType arg in type.TypeArguments) { if (added) @@ -665,7 +665,7 @@ void ConvertXamlTypeToStringHelper(XamlType type, StringBuilder builder) ConvertXamlTypeToStringHelper(arg, builder); added = true; } - builder.Append(")"); + builder.Append(')'); } // re-attach the subscript From 8c8b139855fb27da3b39685d9d36f6aaa20bc8c7 Mon Sep 17 00:00:00 2001 From: lindexi Date: Sun, 17 Jan 2021 11:18:02 +0800 Subject: [PATCH 3/4] Use readonly struct in System.Windows.Input.Manipulations.PointF --- .../Manipulations/ManipulationSequence.cs | 8 ++++---- .../Windows/Input/Manipulations/PointF.cs | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs index 6fa348ae4a4..63f7fd5987d 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs @@ -999,7 +999,7 @@ private void InitializeManipulationState(Int64 timestamp) /// the new expansion /// the new orientation /// the time of the new values - private void OverwriteManipulationState(PointF position, float scale, float expansion, float orientation, Int64 timestamp) + private void OverwriteManipulationState(in PointF position, float scale, float expansion, float orientation, Int64 timestamp) { this.currentManipulationState = new ManipulationState(position, scale, expansion, orientation, timestamp); #if DEBUG @@ -1033,7 +1033,7 @@ private PointF GetAveragePoint() /// /// the common point of reference /// manipulation settings - private void SetVectorsFromPoint(PointF referenceOrigin, ISettings settings) + private void SetVectorsFromPoint(in PointF referenceOrigin, ISettings settings) { Debug.Assert(this.manipulatorStates != null && this.manipulatorStates.Count > 0); @@ -1549,7 +1549,7 @@ private struct ManipulationState public readonly float Orientation; public Int64 Timestamp; - public ManipulationState(PointF position, float scale, float expansion, float orientation, Int64 timestamp) + public ManipulationState(in PointF position, float scale, float expansion, float orientation, Int64 timestamp) { Debug.Assert(!float.IsNaN(position.X) && !float.IsNaN(position.Y)); Debug.Assert(!float.IsInfinity(position.Y) && !float.IsInfinity(position.Y)); @@ -1589,4 +1589,4 @@ private enum ProcessorState #endregion Private Classes } -} \ No newline at end of file +} diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/PointF.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/PointF.cs index 6b6f2ca4d31..c8230d99770 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/PointF.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/PointF.cs @@ -13,10 +13,10 @@ namespace System.Windows.Input.Manipulations /// two floats everywhere, but I just couldn't take it any more. A point class is just /// too nice a thing. /// - internal struct PointF + internal readonly struct PointF { - private float x; - private float y; + private readonly float x; + private readonly float y; /// /// Create a basic point structure @@ -36,7 +36,7 @@ public PointF(float x, float y) /// The point to convert. /// A VectorF structure with an X value equal to this point's X value /// and a Y value equal to this point's Y value. - public static explicit operator VectorF(PointF point) + public static explicit operator VectorF(in PointF point) { return new VectorF(point.x, point.y); } @@ -47,7 +47,7 @@ public static explicit operator VectorF(PointF point) /// /// /// - public static bool operator !=(PointF left, PointF right) + public static bool operator !=(in PointF left, in PointF right) { return left.X != right.X || left.Y != right.Y; } @@ -61,7 +61,7 @@ public static explicit operator VectorF(PointF point) /// /// /// - public static bool operator ==(PointF left, PointF right) + public static bool operator ==(in PointF left, in PointF right) { return left.X == right.X && left.Y == right.Y; } @@ -73,7 +73,7 @@ public static explicit operator VectorF(PointF point) /// The point to translate. /// The amount by which to translate the point. /// The result of translating the specified point by the specified vector. - public static PointF operator +(PointF pt, VectorF offset) + public static PointF operator +(in PointF pt, VectorF offset) { return new PointF(pt.X + offset.X, pt.Y + offset.Y); } @@ -85,7 +85,7 @@ public static explicit operator VectorF(PointF point) /// The point from which point2 is subtracted. /// The point to subtract from point1. /// The difference between point1 and point2. - public static VectorF operator -(PointF point1, PointF point2) + public static VectorF operator -(in PointF point1, in PointF point2) { return new VectorF(point1.x - point2.x, point1.y - point2.y); } @@ -97,7 +97,7 @@ public static explicit operator VectorF(PointF point) /// The point from which vector is subtracted. /// The vector to subtract from point /// The difference between point and vector. - public static PointF operator -(PointF point, VectorF vector) + public static PointF operator -(in PointF point, VectorF vector) { return new PointF(point.x - vector.X, point.y - vector.Y); } From effee7db7a8c7c27bc85c4fbe553eb85bc5d5dc9 Mon Sep 17 00:00:00 2001 From: Ryland <41491307+ryalanms@users.noreply.github.com> Date: Wed, 27 Jan 2021 13:44:11 -0800 Subject: [PATCH 4/4] Remove method with the same signature created in two different PRs --- .../MS/Internal/Tasks/CompilerState.cs | 45 ++++++++++++++++++- .../System/Xaml/MS/Impl/KnownStrings.cs | 8 ---- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerState.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerState.cs index 131d3b47b73..72b93dac45d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerState.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerState.cs @@ -215,7 +215,7 @@ internal static string GenerateCacheForFileList(ITaskItem[] fileItemList) for (int i = 0; i < iCount; i++) { - iHashCode += fileItemList[i].ItemSpec.GetHashCode(); + iHashCode += GetNonRandomizedHashCode(fileItemList[i].ItemSpec); } StringBuilder sb = new StringBuilder(); @@ -251,6 +251,49 @@ private static string GenerateStringFromFileNames(ITaskItem[] fileItemList) return fileNames; } + // + // Generates a stable hash code value for strings. + // In .NET Core the hash values for the same string can be different between + // subsequent program runs and cannot be used for caching here. + // Copied from String.Comparison.cs + // + private static unsafe int GetNonRandomizedHashCode(string str) + { + fixed (char* src = str) + { + Debug.Assert(src[str.Length] == '\0', "src[str.Length] == '\\0'"); + Debug.Assert(((int)src) % 4 == 0, "Managed string should start at 4 bytes boundary"); + + uint hash1 = (5381 << 16) + 5381; + uint hash2 = hash1; + + uint* ptr = (uint*)src; + int length = str.Length; + + while (length > 2) + { + length -= 4; + // Where length is 4n-1 (e.g. 3,7,11,15,19) this additionally consumes the null terminator + hash1 = (RotateLeft(hash1, 5) + hash1) ^ ptr[0]; + hash2 = (RotateLeft(hash2, 5) + hash2) ^ ptr[1]; + ptr += 2; + } + + if (length > 0) + { + // Where length is 4n-3 (e.g. 1,5,9,13,17) this additionally consumes the null terminator + hash2 = (RotateLeft(hash2, 5) + hash2) ^ ptr[0]; + } + + return (int)(hash1 + (hash2 * 1566083941)); + } + } + + private static uint RotateLeft(uint value, int offset) + { + return (value << offset) | (value >> (32 - offset)); + } + #endregion #region internal properties diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs index c94c988ffd2..c3d6341f5ac 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs @@ -62,14 +62,6 @@ public static bool Eq(string a, string b) return string.Equals(a, b, StringComparison.Ordinal); } - /// - /// Standard String Index search operation. - /// - public static int IndexOf(string src, char value) - { - return src.IndexOf(value); - } - /// /// Standard String Index search operation. ///