Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ValueStringBuilder.cs
Go to the documentation of this file.
1
using
System.Buffers
;
2
using
System.Reflection
;
3
using
System.Runtime.CompilerServices
;
4
5
namespace
System.Text
;
6
7
[DefaultMember(
"Item"
)]
8
internal
ref struct
ValueStringBuilder
9
{
10
private
char
[]
_arrayToReturnToPool
;
11
12
private
Span<char>
_chars
;
13
14
private
int
_pos
;
15
16
public
ValueStringBuilder
(
Span<char>
initialBuffer)
17
{
18
_arrayToReturnToPool
=
null
;
19
_chars
= initialBuffer;
20
_pos
= 0;
21
}
22
23
public
override
string
ToString
()
24
{
25
string
result =
_chars
.
Slice
(0,
_pos
).ToString();
26
Dispose
();
27
return
result;
28
}
29
30
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
31
public
void
Append
(
char
c)
32
{
33
int
pos =
_pos
;
34
if
((uint)pos < (uint)
_chars
.
Length
)
35
{
36
_chars
[pos] = c;
37
_pos
= pos + 1;
38
}
39
else
40
{
41
GrowAndAppend
(c);
42
}
43
}
44
45
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
46
public
void
Append
(
string
s
)
47
{
48
if
(
s
!=
null
)
49
{
50
int
pos =
_pos
;
51
if
(
s
.Length == 1 && (uint)pos < (uint)
_chars
.
Length
)
52
{
53
_chars
[pos] =
s
[0];
54
_pos
= pos + 1;
55
}
56
else
57
{
58
AppendSlow
(
s
);
59
}
60
}
61
}
62
63
private
void
AppendSlow
(
string
s
)
64
{
65
int
pos =
_pos
;
66
if
(pos >
_chars
.
Length
-
s
.Length)
67
{
68
Grow
(
s
.Length);
69
}
70
s
.CopyTo(
_chars
.
Slice
(pos));
71
_pos
+=
s
.Length;
72
}
73
74
public
void
Append
(
ReadOnlySpan<char>
value
)
75
{
76
int
pos =
_pos
;
77
if
(pos >
_chars
.
Length
-
value
.Length)
78
{
79
Grow
(
value
.Length);
80
}
81
value
.CopyTo(
_chars
.
Slice
(
_pos
));
82
_pos
+=
value
.Length;
83
}
84
85
[MethodImpl(
MethodImplOptions
.NoInlining)]
86
private
void
GrowAndAppend
(
char
c)
87
{
88
Grow
(1);
89
Append
(c);
90
}
91
92
[MethodImpl(
MethodImplOptions
.NoInlining)]
93
private
void
Grow
(
int
additionalCapacityBeyondPos)
94
{
95
char
[]
array
=
ArrayPool<char>
.
Shared
.Rent((
int
)
Math
.
Max
((uint)(
_pos
+ additionalCapacityBeyondPos), (uint)(
_chars
.
Length
* 2)));
96
_chars
.
Slice
(0,
_pos
).CopyTo(
array
);
97
char
[] arrayToReturnToPool =
_arrayToReturnToPool
;
98
_chars
= (
_arrayToReturnToPool
=
array
);
99
if
(arrayToReturnToPool !=
null
)
100
{
101
ArrayPool<char>
.
Shared
.Return(arrayToReturnToPool);
102
}
103
}
104
105
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
106
public
void
Dispose
()
107
{
108
char
[] arrayToReturnToPool =
_arrayToReturnToPool
;
109
this
=
default
(
System
.
Text
.
ValueStringBuilder
);
110
if
(arrayToReturnToPool !=
null
)
111
{
112
ArrayPool<char>
.
Shared
.Return(arrayToReturnToPool);
113
}
114
}
115
}
System.Buffers.ArrayPool.Shared
static ArrayPool< T > Shared
Definition
ArrayPool.cs:7
System.Buffers.ArrayPool
Definition
ArrayPool.cs:4
System.Math.Max
static byte Max(byte val1, byte val2)
Definition
Math.cs:738
System.Math
Definition
Math.cs:13
System.Buffers
Definition
Base64.cs:7
System.Reflection
Definition
ICustomTypeProvider.cs:1
System.Runtime.CompilerServices.MethodImplOptions
MethodImplOptions
Definition
MethodImplOptions.cs:5
System.Runtime.CompilerServices
Definition
NullablePublicOnlyAttribute.cs:3
System.Text
Definition
ConsoleEncoding.cs:1
System.ExceptionArgument.s
@ s
System.ExceptionArgument.value
@ value
System.ExceptionArgument.array
@ array
System
Definition
BlockingCollection.cs:8
System.ReadOnlySpan
Definition
ReadOnlySpan.cs:14
System.Span.Slice
Span< T > Slice(int start)
Definition
Span.cs:271
System.Span.Length
int Length
Definition
Span.cs:70
System.Span
Definition
Span.cs:14
System.Text.ValueStringBuilder.GrowAndAppend
void GrowAndAppend(char c)
Definition
ValueStringBuilder.cs:121
System.Text.ValueStringBuilder.Dispose
void Dispose()
Definition
ValueStringBuilder.cs:68
System.Text.ValueStringBuilder.ValueStringBuilder
ValueStringBuilder(Span< char > initialBuffer)
Definition
ValueStringBuilder.cs:16
System.Text.ValueStringBuilder.Append
void Append(string s)
Definition
ValueStringBuilder.cs:46
System.Text.ValueStringBuilder.ToString
override string ToString()
Definition
ValueStringBuilder.cs:23
System.Text.ValueStringBuilder._arrayToReturnToPool
char[] _arrayToReturnToPool
Definition
ValueStringBuilder.cs:11
System.Text.ValueStringBuilder._chars
Span< char > _chars
Definition
ValueStringBuilder.cs:13
System.Text.ValueStringBuilder._pos
int _pos
Definition
ValueStringBuilder.cs:15
System.Text.ValueStringBuilder.Append
void Append(ReadOnlySpan< char > value)
Definition
ValueStringBuilder.cs:74
System.Text.ValueStringBuilder.Append
void Append(char c)
Definition
ValueStringBuilder.cs:31
System.Text.ValueStringBuilder.Grow
void Grow(int additionalCapacityBeyondPos)
Definition
ValueStringBuilder.cs:55
System.Text.ValueStringBuilder.AppendSlow
void AppendSlow(string s)
Definition
ValueStringBuilder.cs:84
System.Text.ValueStringBuilder
Definition
ValueStringBuilder.cs:10
source
System.Net.Http
System.Text
ValueStringBuilder.cs
Generated by
1.10.0