Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [SecuritySafeCritical]
- [__DynamicallyInvokable]
- public unsafe StringBuilder Append(string value)
- {
- if (value != null)
- {
- char[] chunkChars = this.m_ChunkChars;
- int chunkLength = this.m_ChunkLength;
- int length = value.Length;
- int num = chunkLength + length;
- if (num < chunkChars.Length)
- {
- if (length <= 2)
- {
- if (length > 0)
- chunkChars[chunkLength] = value[0];
- if (length > 1)
- chunkChars[chunkLength + 1] = value[1];
- }
- else
- {
- fixed (char* smem = value)
- fixed (char* dmem = &chunkChars[chunkLength])
- string.wstrcpy(dmem, smem, length);
- }
- this.m_ChunkLength = num;
- }
- else
- this.AppendHelper(value);
- }
- return this;
- }
- [__DynamicallyInvokable]
- public StringBuilder Append(char value, int repeatCount)
- {
- if (repeatCount < 0)
- throw new ArgumentOutOfRangeException(nameof (repeatCount), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
- if (repeatCount == 0)
- return this;
- int num = this.m_ChunkLength;
- while (repeatCount > 0)
- {
- if (num < this.m_ChunkChars.Length)
- {
- this.m_ChunkChars[num++] = value;
- --repeatCount;
- }
- else
- {
- this.m_ChunkLength = num;
- this.ExpandByABlock(repeatCount);
- num = 0;
- }
- }
- this.m_ChunkLength = num;
- return this;
- }
- private void ExpandByABlock(int minBlockCharCount)
- {
- if (minBlockCharCount + this.Length < minBlockCharCount || minBlockCharCount + this.Length > this.m_MaxCapacity)
- throw new ArgumentOutOfRangeException("requiredLength", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity"));
- int length = Math.Max(minBlockCharCount, Math.Min(this.Length, 8000));
- this.m_ChunkPrevious = new StringBuilder(this);
- this.m_ChunkOffset += this.m_ChunkLength;
- this.m_ChunkLength = 0;
- if (this.m_ChunkOffset + length < length)
- {
- this.m_ChunkChars = (char[]) null;
- throw new OutOfMemoryException();
- }
- this.m_ChunkChars = new char[length];
- }
Advertisement
Add Comment
Please, Sign In to add comment