com.wallstop-studios.dxmessaging 2.0.0-rc26.7 → 2.0.0-rc26.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,6 +51,7 @@ namespace DxMessaging.Core.DataStructure
51
51
  public int Count { get; private set; }
52
52
 
53
53
  private readonly List<T> _buffer;
54
+ private readonly List<T> _cache = new();
54
55
  private int _position;
55
56
 
56
57
  public T this[int index]
@@ -132,21 +133,24 @@ namespace DxMessaging.Core.DataStructure
132
133
  return false;
133
134
  }
134
135
 
135
- int write = 0;
136
- bool removed = false;
137
136
  comparer ??= EqualityComparer<T>.Default;
137
+
138
+ _cache.Clear();
138
139
  for (int i = 0; i < Count; ++i)
139
140
  {
140
- int readIdx = AdjustedIndexFor(i);
141
- T item = _buffer[readIdx];
141
+ _cache.Add(_buffer[AdjustedIndexFor(i)]);
142
+ }
142
143
 
143
- if (!removed && comparer.Equals(item, element))
144
+ // Find and remove the element
145
+ bool removed = false;
146
+ for (int i = 0; i < _cache.Count; ++i)
147
+ {
148
+ if (comparer.Equals(_cache[i], element))
144
149
  {
150
+ _cache.RemoveAt(i);
145
151
  removed = true;
146
- continue;
152
+ break;
147
153
  }
148
-
149
- _buffer[write++] = item;
150
154
  }
151
155
 
152
156
  if (!removed)
@@ -154,9 +158,10 @@ namespace DxMessaging.Core.DataStructure
154
158
  return false;
155
159
  }
156
160
 
157
- _buffer.RemoveRange(write, _buffer.Count - write);
158
-
159
- Count--;
161
+ // Rebuild the buffer with linearized data
162
+ _buffer.Clear();
163
+ _buffer.AddRange(_cache);
164
+ Count = _cache.Count;
160
165
  _position = Count < Capacity ? Count : 0;
161
166
  return true;
162
167
  }
@@ -9,29 +9,36 @@ namespace DxMessaging.Core.Extensions
9
9
  internal static bool HasFlagNoAlloc<T>(this T value, T flag)
10
10
  where T : unmanaged, Enum
11
11
  {
12
- ulong valueUnderlying = GetUInt64(value);
13
- ulong flagUnderlying = GetUInt64(flag);
14
- return (valueUnderlying & flagUnderlying) == flagUnderlying;
12
+ ulong? valueUnderlying = GetUInt64(value);
13
+ ulong? flagUnderlying = GetUInt64(flag);
14
+ if (valueUnderlying == null || flagUnderlying == null)
15
+ {
16
+ // Fallback for unsupported enum sizes
17
+ return value.HasFlag(flag);
18
+ }
19
+
20
+ return (valueUnderlying.Value & flagUnderlying.Value) == flagUnderlying.Value;
15
21
  }
16
22
 
17
23
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
18
- private static unsafe ulong GetUInt64<T>(T value)
24
+ private static ulong? GetUInt64<T>(T value)
19
25
  where T : unmanaged
20
26
  {
21
- /*
22
- Works because T is constrained to unmanaged, so it's safe to reinterpret
23
- All enums are value types and have a fixed size
24
- */
25
- return sizeof(T) switch
27
+ try
28
+ {
29
+ return Unsafe.SizeOf<T>() switch
30
+ {
31
+ 1 => Unsafe.As<T, byte>(ref value),
32
+ 2 => Unsafe.As<T, ushort>(ref value),
33
+ 4 => Unsafe.As<T, uint>(ref value),
34
+ 8 => Unsafe.As<T, ulong>(ref value),
35
+ _ => null,
36
+ };
37
+ }
38
+ catch
26
39
  {
27
- 1 => *(byte*)&value,
28
- 2 => *(ushort*)&value,
29
- 4 => *(uint*)&value,
30
- 8 => *(ulong*)&value,
31
- _ => throw new ArgumentException(
32
- $"Unsupported enum size: {sizeof(T)} for type {typeof(T)}"
33
- ),
34
- };
40
+ return null;
41
+ }
35
42
  }
36
43
  }
37
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.dxmessaging",
3
- "version": "2.0.0-rc26.7",
3
+ "version": "2.0.0-rc26.9",
4
4
  "displayName": "DxMessaging",
5
5
  "description": "Synchronous Event Bus for Unity",
6
6
  "unity": "2021.3",
@@ -32,10 +32,3 @@
32
32
  "test": "echo \"Error: no test specified\" && exit 1"
33
33
  }
34
34
  }
35
-
36
-
37
-
38
-
39
-
40
-
41
-