remove double bound check from StringBuilder.Append(char) (dotnet/coreclr#27340)
authorAdam Sitnik <adam.sitnik@gmail.com>
Tue, 22 Oct 2019 05:03:40 +0000 (07:03 +0200)
committerGitHub <noreply@github.com>
Tue, 22 Oct 2019 05:03:40 +0000 (07:03 +0200)
Commit migrated from https://github.com/dotnet/coreclr/commit/46bffce7ee839a0d0d18801a6795e8d6d40ad728

src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs

index 1d0f6ed..8af8e91 100644 (file)
@@ -1152,9 +1152,13 @@ namespace System.Text
 
         public StringBuilder Append(char value)
         {
-            if (m_ChunkLength < m_ChunkChars.Length)
+            int nextCharIndex = m_ChunkLength;
+            char[] chars = m_ChunkChars;
+
+            if ((uint)chars.Length > (uint)nextCharIndex)
             {
-                m_ChunkChars[m_ChunkLength++] = value;
+                chars[nextCharIndex] = value;
+                m_ChunkLength++;
             }
             else
             {