Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ValueListBuilder.cs
Go to the documentation of this file.
1
using
System.Buffers
;
2
using
System.Runtime.CompilerServices
;
3
4
namespace
System.Collections.Generic
;
5
6
internal
ref struct
ValueListBuilder
<T>
7
{
8
private
Span<T>
_span
;
9
10
private
T[]
_arrayFromPool
;
11
12
private
int
_pos
;
13
14
public
int
Length
15
{
16
get
17
{
18
return
_pos
;
19
}
20
set
21
{
22
_pos
=
value
;
23
}
24
}
25
26
public
ref
T
this
[
int
index
] =>
ref
_span
[
index
];
27
28
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
29
public
T
Pop
()
30
{
31
_pos
--;
32
return
_span
[
_pos
];
33
}
34
35
public
ValueListBuilder
(
Span<T>
initialSpan
)
36
{
37
_span
=
initialSpan
;
38
_arrayFromPool
=
null
;
39
_pos
= 0;
40
}
41
42
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
43
public
void
Append
(T
item
)
44
{
45
int
pos =
_pos
;
46
if
(pos >=
_span
.Length)
47
{
48
Grow
();
49
}
50
_span
[pos] =
item
;
51
_pos
= pos + 1;
52
}
53
54
public
ReadOnlySpan<T>
AsSpan
()
55
{
56
return
_span
.Slice(0,
_pos
);
57
}
58
59
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
60
public
void
Dispose
()
61
{
62
T[]
arrayFromPool
=
_arrayFromPool
;
63
if
(
arrayFromPool
!=
null
)
64
{
65
_arrayFromPool
=
null
;
66
ArrayPool<T>
.Shared.Return(
arrayFromPool
);
67
}
68
}
69
70
private
void
Grow
()
71
{
72
T[]
array
=
ArrayPool<T>
.Shared.Rent(
_span
.Length * 2);
73
bool
flag =
_span
.TryCopyTo(
array
);
74
T[]
arrayFromPool
=
_arrayFromPool
;
75
_span
= (
_arrayFromPool
=
array
);
76
if
(
arrayFromPool
!=
null
)
77
{
78
ArrayPool<T>
.Shared.Return(
arrayFromPool
);
79
}
80
}
81
}
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Buffers
Definition
Base64.cs:7
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Runtime.CompilerServices.MethodImplOptions
MethodImplOptions
Definition
MethodImplOptions.cs:5
System.Runtime.CompilerServices
Definition
NullablePublicOnlyAttribute.cs:3
System.ExceptionArgument.value
@ value
System.ExceptionArgument.item
@ item
System.ExceptionArgument.index
@ index
System.ExceptionArgument.array
@ array
System.Collections.Generic.ValueListBuilder.AsSpan
ReadOnlySpan< T > AsSpan()
Definition
ValueListBuilder.cs:54
System.Collections.Generic.ValueListBuilder.Append
void Append(T item)
Definition
ValueListBuilder.cs:43
System.Collections.Generic.ValueListBuilder.Length
int Length
Definition
ValueListBuilder.cs:16
System.Collections.Generic.ValueListBuilder._span
Span< T > _span
Definition
ValueListBuilder.cs:10
System.Collections.Generic.ValueListBuilder.Grow
void Grow()
Definition
ValueListBuilder.cs:53
System.Collections.Generic.ValueListBuilder.Dispose
void Dispose()
Definition
ValueListBuilder.cs:60
System.Collections.Generic.ValueListBuilder._arrayFromPool
T[] _arrayFromPool
Definition
ValueListBuilder.cs:12
System.Collections.Generic.ValueListBuilder.ValueListBuilder
ValueListBuilder(Span< T > initialSpan)
Definition
ValueListBuilder.cs:35
System.Collections.Generic.ValueListBuilder.Pop
T Pop()
Definition
ValueListBuilder.cs:29
System.Collections.Generic.ValueListBuilder._pos
int _pos
Definition
ValueListBuilder.cs:14
System.Collections.Generic.ValueListBuilder
Definition
ValueListBuilder.cs:7
source
System.Text.RegularExpressions
System.Collections.Generic
ValueListBuilder.cs
Generated by
1.10.0