Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SegmentStringBuilder.cs
Go to the documentation of this file.
4
5namespace System.Text;
6
7[DebuggerDisplay("Count = {_count}")]
8internal struct SegmentStringBuilder
9{
11
12 private int _count;
13
14 public int Count => _count;
15
17 {
19 result._array = Array.Empty<ReadOnlyMemory<char>>();
20 return result;
21 }
22
23 [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 public void Add(ReadOnlyMemory<char> segment)
25 {
27 int count = _count;
28 if ((uint)count < (uint)array.Length)
29 {
30 array[count] = segment;
31 _count = count + 1;
32 }
33 else
34 {
35 GrowAndAdd(segment);
36 }
37 }
38
39 [MethodImpl(MethodImplOptions.NoInlining)]
40 private void GrowAndAdd(ReadOnlyMemory<char> segment)
41 {
43 int minimumLength = ((array.Length == 0) ? 256 : (array.Length * 2));
44 ReadOnlyMemory<char>[] array2 = (_array = ArrayPool<ReadOnlyMemory<char>>.Shared.Rent(minimumLength));
45 Array.Copy(array, array2, _count);
46 ArrayPool<ReadOnlyMemory<char>>.Shared.Return(array, clearArray: true);
47 array2[_count++] = segment;
48 }
49
54
55 public override string ToString()
56 {
59 int num = 0;
60 for (int i = 0; i < span.Length; i++)
61 {
62 num += span[i].Length;
63 }
64 string result = string.Create(num, this, delegate(Span<char> dest, SegmentStringBuilder builder)
65 {
66 Span<ReadOnlyMemory<char>> span2 = builder.AsSpan();
67 for (int j = 0; j < span2.Length; j++)
68 {
69 ReadOnlySpan<char> span3 = span2[j].Span;
70 span3.CopyTo(dest);
71 dest = dest.Slice(span3.Length);
72 }
73 });
74 span.Clear();
75 this = default(SegmentStringBuilder);
77 return result;
78 }
79}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
void CopyTo(Span< T > destination)
Span(T[]? array)
Definition Span.cs:90
Span< T > Slice(int start)
Definition Span.cs:271
unsafe void Clear()
Definition Span.cs:198
int Length
Definition Span.cs:70
void Add(ReadOnlyMemory< char > segment)
static SegmentStringBuilder Create()
Span< ReadOnlyMemory< char > > AsSpan()
void GrowAndAdd(ReadOnlyMemory< char > segment)