From 10ef5479688339aaa244f5b343025155ef30c034 Mon Sep 17 00:00:00 2001 From: Alex Perovich Date: Fri, 24 Mar 2017 11:40:21 -0700 Subject: [PATCH] Use Array.Copy with index and remove coreclr specific function Commit migrated from https://github.com/dotnet/coreclr/commit/6e9f1b4a2b98a6a268a69816d80f80063686b7b2 --- .../mscorlib/shared/System/Text/StringBuilder.cs | 35 ++-------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/src/coreclr/src/mscorlib/shared/System/Text/StringBuilder.cs b/src/coreclr/src/mscorlib/shared/System/Text/StringBuilder.cs index f6dd1ab..df1a889 100644 --- a/src/coreclr/src/mscorlib/shared/System/Text/StringBuilder.cs +++ b/src/coreclr/src/mscorlib/shared/System/Text/StringBuilder.cs @@ -322,7 +322,7 @@ namespace System.Text { int newLen = value - m_ChunkOffset; char[] newArray = new char[newLen]; - Array.Copy(m_ChunkChars, newArray, m_ChunkLength); + Array.Copy(m_ChunkChars, 0, newArray, 0, m_ChunkLength); m_ChunkChars = newArray; } } @@ -532,7 +532,7 @@ namespace System.Text char[] newArray = new char[newLen]; Debug.Assert(newLen > chunk.m_ChunkChars.Length, "the new chunk should be larger than the one it is replacing"); - Array.Copy(chunk.m_ChunkChars, newArray, chunk.m_ChunkLength); + Array.Copy(chunk.m_ChunkChars, 0, newArray, 0, chunk.m_ChunkLength); m_ChunkChars = newArray; m_ChunkPrevious = chunk.m_ChunkPrevious; @@ -2141,37 +2141,6 @@ namespace System.Text } } - // Copies the source StringBuilder to the destination IntPtr memory allocated with len bytes. - internal unsafe void InternalCopy(IntPtr dest, int len) - { - if (len == 0) - return; - - bool isLastChunk = true; - byte* dstPtr = (byte*)dest.ToPointer(); - StringBuilder currentSrc = FindChunkForByte(len); - - do - { - int chunkOffsetInBytes = currentSrc.m_ChunkOffset * sizeof(char); - int chunkLengthInBytes = currentSrc.m_ChunkLength * sizeof(char); - fixed (char* charPtr = ¤tSrc.m_ChunkChars[0]) - { - byte* srcPtr = (byte*)charPtr; - if (isLastChunk) - { - isLastChunk = false; - Buffer.Memcpy(dstPtr + chunkOffsetInBytes, srcPtr, len - chunkOffsetInBytes); - } - else - { - Buffer.Memcpy(dstPtr + chunkOffsetInBytes, srcPtr, chunkLengthInBytes); - } - } - currentSrc = currentSrc.m_ChunkPrevious; - } while (currentSrc != null); - } - /// /// Finds the chunk for the logical index (number of characters in the whole stringbuilder) 'index' /// YOu can then get the offset in this chunk by subtracting the m_BlockOffset field from 'index' -- 2.7.4