CallSites for MemoryExtensions.Contains (CoreCLR) (dotnet/coreclr#19874)
authorGrant <grant@jesanna.com>
Wed, 12 Sep 2018 10:19:37 +0000 (03:19 -0700)
committerAhson Khan <ahkha@microsoft.com>
Wed, 12 Sep 2018 10:19:37 +0000 (03:19 -0700)
* Update additional callsites for MemoryExtensions.Contains

* One more callsite

* More callsites

* CR fixes

Commit migrated from https://github.com/dotnet/coreclr/commit/9d8d00c61a65a413768f47267e119fa2d31beb2e

12 files changed:
src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs
src/coreclr/src/System.Private.CoreLib/src/System/Environment.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
src/libraries/System.Private.CoreLib/src/System/Guid.cs
src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs
src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs
src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs
src/libraries/System.Private.CoreLib/src/System/String.Searching.cs

index 236f4f5..48f3fb4 100644 (file)
@@ -1041,7 +1041,7 @@ namespace Microsoft.Win32
         internal static string FixupName(string name)
         {
             Debug.Assert(name != null, "[FixupName]name!=null");
-            if (name.IndexOf('\\') == -1)
+            if (!name.Contains('\\'))
                 return name;
 
             StringBuilder sb = new StringBuilder(name);
index bfd9e06..1b52065 100644 (file)
@@ -420,7 +420,7 @@ namespace System
             {
                 throw new ArgumentException(SR.Argument_StringFirstCharIsZero, nameof(variable));
             }
-            if (variable.IndexOf('=') != -1)
+            if (variable.Contains('='))
             {
                 throw new ArgumentException(SR.Argument_IllegalEnvVarName, nameof(variable));
             }
index 567dca4..ad080ff 100644 (file)
@@ -582,7 +582,7 @@ namespace System.Reflection
             {
                 return true;
             }
-            return (RFC3986ReservedMarks.IndexOf(c) >= 0);
+            return (RFC3986ReservedMarks.Contains(c));
         }
 
         internal static unsafe bool IsUnreserved(char c)
@@ -591,7 +591,7 @@ namespace System.Reflection
             {
                 return true;
             }
-            return (RFC3986UnreservedMarks.IndexOf(c) >= 0);
+            return (RFC3986UnreservedMarks.Contains(c));
         }
 
         //Only consider ASCII characters
index 0c21672..3dc7883 100644 (file)
@@ -174,7 +174,7 @@ namespace System.Diagnostics.Tracing
 
         public static void CheckName(string name)
         {
-            if (name != null && 0 <= name.IndexOf('\0'))
+            if (name != null && name.Contains('\0'))
             {
                 throw new ArgumentOutOfRangeException(nameof(name));
             }
index 61e0691..c94ac0a 100644 (file)
@@ -311,7 +311,7 @@ namespace System.Globalization
                         break;
                     default:
                         const string unsupportedDateFieldSymbols = "YuUrQqwWDFg";
-                        Debug.Assert(unsupportedDateFieldSymbols.IndexOf(input[index]) == -1,
+                        Debug.Assert(!unsupportedDateFieldSymbols.Contains(input[index]),
                             string.Format(CultureInfo.InvariantCulture,
                                 "Encountered an unexpected date field symbol '{0}' from ICU which has no known corresponding .NET equivalent.", 
                                 input[index]));
index fda239c..5eb9f44 100644 (file)
@@ -2268,7 +2268,7 @@ namespace System.Globalization
             for (int i = startIndex; i < format.Length; ++i)
             {
                 // See if we have a time Part
-                if (!inQuote && timeParts.IndexOf(format[i]) != -1)
+                if (!inQuote && timeParts.Contains(format[i]))
                 {
                     return i;
                 }
index c57d3c4..6e6ec06 100644 (file)
@@ -449,7 +449,7 @@ namespace System
             }
 
             // Check for braces
-            bool bracesExistInString = (guidString.IndexOf('{') >= 0);
+            bool bracesExistInString = guidString.Contains('{');
 
             if (bracesExistInString)
             {
@@ -471,7 +471,7 @@ namespace System
             }
 
             // Check for parenthesis
-            bool parenthesisExistInString = (guidString.IndexOf('(') >= 0);
+            bool parenthesisExistInString = guidString.Contains('(');
 
             if (parenthesisExistInString)
             {
index f364b84..ecf71e6 100644 (file)
@@ -23,7 +23,7 @@ namespace System.IO
             if (path.Length == 0)
                 throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
 
-            if (path.IndexOf('\0') != -1)
+            if (path.Contains('\0'))
                 throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path)); 
             
             // Expand with current directory if necessary
index 1c27e0c..ddfd796 100644 (file)
@@ -47,7 +47,7 @@ namespace System.IO
             // Embedded null characters are the only invalid character case we trully care about.
             // This is because the nulls will signal the end of the string to Win32 and therefore have
             // unpredictable results.
-            if (path.IndexOf('\0') != -1)
+            if (path.Contains('\0'))
                 throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
 
             if (PathInternal.IsExtended(path.AsSpan()))
index bada2f5..f9a6495 100644 (file)
@@ -33,7 +33,7 @@ namespace System.IO
 
             // If we have the exact same string we were passed in, don't allocate another string.
             // TryExpandShortName does this input identity check.
-            string result = builder.AsSpan().IndexOf('~') >= 0
+            string result = builder.AsSpan().Contains('~')
                 ? TryExpandShortFileName(ref builder, originalPath: path)
                 : builder.AsSpan().Equals(path.AsSpan(), StringComparison.Ordinal) ? path : builder.ToString();
 
@@ -56,7 +56,7 @@ namespace System.IO
             // Get the full path
             GetFullPathName(path.AsSpan(terminate: true), ref builder);
 
-            string result = builder.AsSpan().IndexOf('~') >= 0
+            string result = builder.AsSpan().Contains('~')
                 ? TryExpandShortFileName(ref builder, originalPath: null)
                 : builder.ToString();
 
index 20fdc61..d6f45d2 100644 (file)
@@ -51,7 +51,7 @@ namespace System
         }
 
         // Adapted from IndexOf(...)
-        public static unsafe bool Contains<T>(ref T searchSpace, T value, int length)
+        public static bool Contains<T>(ref T searchSpace, T value, int length)
                where T : IEquatable<T>
         {
             Debug.Assert(length >= 0);
index 857d64e..7660c52 100644 (file)
@@ -22,10 +22,7 @@ namespace System
             return (IndexOf(value, comparisonType) >= 0);
         }
 
-        public bool Contains(char value)
-        {
-            return IndexOf(value) != -1;
-        }
+        public bool Contains(char value) => SpanHelpers.Contains(ref _firstChar, value, Length);
 
         public bool Contains(char value, StringComparison comparisonType)
         {