Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LabelInstructionCompiler.cs
Go to the documentation of this file.
1
using
System.Collections.Concurrent
;
2
using
System.Collections.Generic
;
3
4
namespace
System.Diagnostics.Metrics
;
5
6
internal
static
class
LabelInstructionCompiler
7
{
8
public
static
AggregatorLookupFunc<TAggregator>
Create<TAggregator>
(
ref
AggregatorStore<TAggregator>
aggregatorStore
,
Func<TAggregator>
createAggregatorFunc
,
ReadOnlySpan
<
KeyValuePair<string, object>
>
labels
)
where
TAggregator :
Aggregator
9
{
10
LabelInstruction
[]
array
=
Compile
(
labels
);
11
Array
.
Sort
(
array
, (
LabelInstruction
a
,
LabelInstruction
b
) =>
string
.CompareOrdinal(
a
.LabelName,
b
.LabelName));
12
int
expectedLabels
=
labels
.Length;
13
switch
(
array
.Length)
14
{
15
case
0:
16
{
17
TAggregator
defaultAggregator
=
aggregatorStore
.GetAggregator();
18
return
delegate
(
ReadOnlySpan
<
KeyValuePair<string, object>
>
l
,
out
TAggregator
aggregator
)
19
{
20
if
(
l
.Length !=
expectedLabels
)
21
{
22
aggregator
=
null
;
23
return
false
;
24
}
25
aggregator
=
defaultAggregator
;
26
return
true
;
27
};
28
}
29
case
1:
30
{
31
StringSequence1
names2
=
new
StringSequence1
(
array
[0].LabelName);
32
ConcurrentDictionary<ObjectSequence1, TAggregator>
labelValuesDictionary2
=
aggregatorStore
.GetLabelValuesDictionary<
StringSequence1
,
ObjectSequence1
>(
in
names2
);
33
LabelInstructionInterpretter<ObjectSequence1, TAggregator>
object2
=
new
LabelInstructionInterpretter<ObjectSequence1, TAggregator>
(
expectedLabels
,
array
,
labelValuesDictionary2
,
createAggregatorFunc
);
34
return
object2
.GetAggregator;
35
}
36
case
2:
37
{
38
StringSequence2
names4
=
new
StringSequence2
(
array
[0].LabelName,
array
[1].LabelName);
39
ConcurrentDictionary<ObjectSequence2, TAggregator>
labelValuesDictionary4
=
aggregatorStore
.GetLabelValuesDictionary<
StringSequence2
,
ObjectSequence2
>(
in
names4
);
40
LabelInstructionInterpretter<ObjectSequence2, TAggregator>
object4
=
new
LabelInstructionInterpretter<ObjectSequence2, TAggregator>
(
expectedLabels
,
array
,
labelValuesDictionary4
,
createAggregatorFunc
);
41
return
object4
.GetAggregator;
42
}
43
case
3:
44
{
45
StringSequence3
names3
=
new
StringSequence3
(
array
[0].LabelName,
array
[1].LabelName,
array
[2].LabelName);
46
ConcurrentDictionary<ObjectSequence3, TAggregator>
labelValuesDictionary3
=
aggregatorStore
.GetLabelValuesDictionary<
StringSequence3
,
ObjectSequence3
>(
in
names3
);
47
LabelInstructionInterpretter<ObjectSequence3, TAggregator>
object3
=
new
LabelInstructionInterpretter<ObjectSequence3, TAggregator>
(
expectedLabels
,
array
,
labelValuesDictionary3
,
createAggregatorFunc
);
48
return
object3
.GetAggregator;
49
}
50
default
:
51
{
52
string
[]
array2
=
new
string
[
array
.Length];
53
for
(
int
i = 0; i <
array
.Length; i++)
54
{
55
array2
[i] =
array
[i].LabelName;
56
}
57
StringSequenceMany
names
=
new
StringSequenceMany
(
array2
);
58
ConcurrentDictionary<ObjectSequenceMany, TAggregator>
labelValuesDictionary
=
aggregatorStore
.GetLabelValuesDictionary<
StringSequenceMany
,
ObjectSequenceMany
>(
in
names
);
59
LabelInstructionInterpretter<ObjectSequenceMany, TAggregator>
@
object
=
new
LabelInstructionInterpretter<ObjectSequenceMany, TAggregator>
(
expectedLabels
,
array
,
labelValuesDictionary
,
createAggregatorFunc
);
60
return
@
object
.GetAggregator;
61
}
62
}
63
}
64
65
private
static
LabelInstruction
[]
Compile
(
ReadOnlySpan
<
KeyValuePair<string, object>
>
labels
)
66
{
67
LabelInstruction
[]
array
=
new
LabelInstruction
[
labels
.Length];
68
for
(
int
i = 0; i <
labels
.Length; i++)
69
{
70
array
[i] =
new
LabelInstruction
(i,
labels
[i].Key);
71
}
72
return
array
;
73
}
74
}
System.Array.Sort
static void Sort(Array array)
Definition
Array.cs:2329
System.Array
Definition
Array.cs:16
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Diagnostics.Metrics.Aggregator
Definition
Aggregator.cs:4
System.Diagnostics.Metrics.LabelInstructionCompiler.Create< TAggregator >
static AggregatorLookupFunc< TAggregator > Create< TAggregator >(ref AggregatorStore< TAggregator > aggregatorStore, Func< TAggregator > createAggregatorFunc, ReadOnlySpan< KeyValuePair< string, object > > labels)
Definition
LabelInstructionCompiler.cs:8
System.Diagnostics.Metrics.LabelInstructionCompiler.Compile
static LabelInstruction[] Compile(ReadOnlySpan< KeyValuePair< string, object > > labels)
Definition
LabelInstructionCompiler.cs:65
System.Diagnostics.Metrics.LabelInstructionCompiler
Definition
LabelInstructionCompiler.cs:7
System.Collections.Concurrent
Definition
BlockingCollection.cs:8
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Diagnostics.Metrics
Definition
AggregationManager.cs:6
System.ExceptionArgument.array
@ array
System.Diagnostics.Metrics.LabelInstruction
Definition
LabelInstruction.cs:4
System.Diagnostics.Metrics.ObjectSequence1
Definition
ObjectSequence1.cs:6
System.Diagnostics.Metrics.ObjectSequence2
Definition
ObjectSequence2.cs:6
System.Diagnostics.Metrics.ObjectSequence3
Definition
ObjectSequence3.cs:6
System.Diagnostics.Metrics.ObjectSequenceMany
Definition
ObjectSequenceMany.cs:4
System.Diagnostics.Metrics.StringSequence1
Definition
StringSequence1.cs:6
System.Diagnostics.Metrics.StringSequence2
Definition
StringSequence2.cs:6
System.Diagnostics.Metrics.StringSequence3
Definition
StringSequence3.cs:6
System.Diagnostics.Metrics.StringSequenceMany
Definition
StringSequenceMany.cs:4
System.ReadOnlySpan
Definition
ReadOnlySpan.cs:14
source
System.Diagnostics.DiagnosticSource
System.Diagnostics.Metrics
LabelInstructionCompiler.cs
Generated by
1.10.0