-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.diff
More file actions
48 lines (45 loc) · 1.65 KB
/
Copy pathupdate.diff
File metadata and controls
48 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--- src/GameUtils/Types/Collections/SynchronizedCollection.cs
+++ src/GameUtils/Types/Collections/SynchronizedCollection.cs
@@ -31,8 +31,7 @@
{
private readonly ConcurrentQueue<Operation<T>> _pending = new();
private readonly SemaphoreSlim _integrating = new(1, 1);
- private T[]? _cachedSnapshot;
- private int _cachedSnapshotCount;
+ private List<T>? _cachedSnapshot;
private volatile bool _dirty = true;
/// <summary>
@@ -114,21 +113,11 @@
{
if (_dirty || _cachedSnapshot is null)
{
- var internalCollection = GetInternal();
- var count = internalCollection.TryGetNonEnumeratedCount(out var c) ? c : internalCollection.Count();
- if (_cachedSnapshot is null || _cachedSnapshot.Length < count)
- {
- _cachedSnapshot = new T[System.Math.Max(count, System.Math.Max((_cachedSnapshot?.Length ?? 0) * 2, 4))];
- }
-
- _cachedSnapshotCount = count;
-
- int idx = 0;
- foreach (var item in internalCollection)
- {
- _cachedSnapshot[idx++] = item;
- }
-
+ _cachedSnapshot ??= new List<T>();
+ _cachedSnapshot.Clear();
+
+ _cachedSnapshot.AddRange(GetInternal());
+
_dirty = false;
}
}
@@ -138,7 +127,7 @@
}
}
- return new ArraySegment<T>(_cachedSnapshot!, 0, _cachedSnapshotCount);
+ return _cachedSnapshot!;
}
/// <summary>