Use 'AsSpan' over 'Substring' in 'System.Private.Xml' (#48277)
authorNewell Clark <newellofthefuture@gmail.com>
Mon, 15 Feb 2021 03:47:28 +0000 (22:47 -0500)
committerGitHub <noreply@github.com>
Mon, 15 Feb 2021 03:47:28 +0000 (22:47 -0500)
* Fix violation in System.Private.Xml

- Prefer 'AsSpan' over 'Substring' when span-based overloads are available.

* Update src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeIdentifier.cs

Apply suggested optimization.

Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeIdentifier.cs

index 89afc4d..1938972 100644 (file)
@@ -283,7 +283,7 @@ namespace System.Xml.Serialization
             {
                 if (separator >= 0)
                 {
-                    sb.Append(originalIdentifier.Substring(separator, 1));
+                    sb.Append(originalIdentifier[separator]);
                 }
                 separator++;
                 separator += names[i].Length;