Skip to content

Commit b41b1ce

Browse files
Simplify the code even more
1 parent 89f8b81 commit b41b1ce

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

com.unity.multiplayer.mlapi/Runtime/Profiling/PerformanceDataManager.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,7 @@ internal static void Increment(string fieldName, int count = 1)
2323

2424
internal static void AddTransportData(IReadOnlyDictionary<string, int> transportProfilerData)
2525
{
26-
if (s_ProfilerData == null)
27-
{
28-
return;
29-
}
30-
31-
IEnumerable<KeyValuePair<string, int>> nonDuplicates = transportProfilerData.Where(entry => !s_ProfilerData.tickData.HasData(entry.Key));
32-
foreach (KeyValuePair<string, int> entry in nonDuplicates)
33-
{
34-
s_ProfilerData.tickData.Add(entry.Key, entry.Value);
35-
}
26+
s_ProfilerData?.AddNonDuplicateData(transportProfilerData);
3627
}
3728

3829
internal static PerformanceTickData GetData()
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
namespace MLAPI.Profiling
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace MLAPI.Profiling
25
{
36
public class PerformanceTickData
47
{
58
public int tickID;
69

7-
public readonly ProfilingDataStore tickData = new ProfilingDataStore();
10+
readonly ProfilingDataStore m_TickData = new ProfilingDataStore();
811

912
public void Increment(string fieldName, int count = 1)
1013
{
11-
tickData.Increment(fieldName, count);
14+
m_TickData.Increment(fieldName, count);
15+
}
16+
17+
public void AddNonDuplicateData(IReadOnlyDictionary<string, int> transportProfilerData)
18+
{
19+
IEnumerable<KeyValuePair<string, int>> nonDuplicates = transportProfilerData.Where(entry => !m_TickData.HasData(entry.Key));
20+
foreach (KeyValuePair<string, int> entry in nonDuplicates)
21+
{
22+
m_TickData.Add(entry.Key, entry.Value);
23+
}
1224
}
1325

1426
public int GetData(string fieldName)
1527
{
16-
return tickData.GetData(fieldName);
28+
return m_TickData.GetData(fieldName);
1729
}
1830
}
1931
}

com.unity.multiplayer.mlapi/Runtime/Profiling/ProfilingDataStore.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace MLAPI.Profiling
45
{
56
public class ProfilingDataStore
67
{
78
readonly Dictionary<string, int> m_Dictionary = new Dictionary<string, int>();
89

9-
public void Add(string entryKey, int entryValue)
10+
public void Add(string fieldName, int value)
1011
{
11-
m_Dictionary.Add(entryKey, entryValue);
12+
m_Dictionary.Add(fieldName, value);
1213
}
1314

1415
public void Increment(string fieldName, int count = 1)
1516
{
16-
if (!m_Dictionary.ContainsKey(fieldName))
17-
{
18-
m_Dictionary[fieldName] = 0;
19-
}
20-
21-
m_Dictionary[fieldName] += count;
17+
m_Dictionary[fieldName] = m_Dictionary.ContainsKey(fieldName) ? m_Dictionary[fieldName] + count : count;
2218
}
2319

2420
public bool HasData(string fieldName)

0 commit comments

Comments
 (0)