From 1f9581b6d76359ea38dbc890392026ce65cd247b Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 22 Oct 2019 07:03:40 +0200 Subject: [PATCH] remove double bound check from StringBuilder.Append(char) (dotnet/coreclr#27340) Commit migrated from https://github.com/dotnet/coreclr/commit/46bffce7ee839a0d0d18801a6795e8d6d40ad728 --- .../System.Private.CoreLib/src/System/Text/StringBuilder.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs index 1d0f6ed6..8af8e91 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs @@ -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 { -- 2.7.4