nahidjamalli

Untitled

Jan 24th, 2020
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. [SecuritySafeCritical]
  2. [__DynamicallyInvokable]
  3. public unsafe StringBuilder Append(string value)
  4. {
  5. if (value != null)
  6. {
  7. char[] chunkChars = this.m_ChunkChars;
  8. int chunkLength = this.m_ChunkLength;
  9. int length = value.Length;
  10. int num = chunkLength + length;
  11. if (num < chunkChars.Length)
  12. {
  13. if (length <= 2)
  14. {
  15. if (length > 0)
  16. chunkChars[chunkLength] = value[0];
  17. if (length > 1)
  18. chunkChars[chunkLength + 1] = value[1];
  19. }
  20. else
  21. {
  22. fixed (char* smem = value)
  23. fixed (char* dmem = &chunkChars[chunkLength])
  24. string.wstrcpy(dmem, smem, length);
  25. }
  26. this.m_ChunkLength = num;
  27. }
  28. else
  29. this.AppendHelper(value);
  30. }
  31. return this;
  32. }
  33.  
  34. [__DynamicallyInvokable]
  35. public StringBuilder Append(char value, int repeatCount)
  36. {
  37. if (repeatCount < 0)
  38. throw new ArgumentOutOfRangeException(nameof (repeatCount), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
  39. if (repeatCount == 0)
  40. return this;
  41. int num = this.m_ChunkLength;
  42. while (repeatCount > 0)
  43. {
  44. if (num < this.m_ChunkChars.Length)
  45. {
  46. this.m_ChunkChars[num++] = value;
  47. --repeatCount;
  48. }
  49. else
  50. {
  51. this.m_ChunkLength = num;
  52. this.ExpandByABlock(repeatCount);
  53. num = 0;
  54. }
  55. }
  56. this.m_ChunkLength = num;
  57. return this;
  58. }
  59.  
  60. private void ExpandByABlock(int minBlockCharCount)
  61. {
  62. if (minBlockCharCount + this.Length < minBlockCharCount || minBlockCharCount + this.Length > this.m_MaxCapacity)
  63. throw new ArgumentOutOfRangeException("requiredLength", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity"));
  64. int length = Math.Max(minBlockCharCount, Math.Min(this.Length, 8000));
  65. this.m_ChunkPrevious = new StringBuilder(this);
  66. this.m_ChunkOffset += this.m_ChunkLength;
  67. this.m_ChunkLength = 0;
  68. if (this.m_ChunkOffset + length < length)
  69. {
  70. this.m_ChunkChars = (char[]) null;
  71. throw new OutOfMemoryException();
  72. }
  73. this.m_ChunkChars = new char[length];
  74. }
Advertisement
Add Comment
Please, Sign In to add comment