Use Array.Copy with index and remove coreclr specific function
authorAlex Perovich <alperovi@microsoft.com>
Fri, 24 Mar 2017 18:40:21 +0000 (11:40 -0700)
committerdotnet-bot <dotnet-bot@microsoft.com>
Fri, 24 Mar 2017 20:13:53 +0000 (20:13 +0000)
Commit migrated from https://github.com/dotnet/coreclr/commit/6e9f1b4a2b98a6a268a69816d80f80063686b7b2

src/coreclr/src/mscorlib/shared/System/Text/StringBuilder.cs

index f6dd1ab..df1a889 100644 (file)
@@ -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 = &currentSrc.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);
-        }
-
         /// <summary>
         /// 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'