perf(eventbus): remove inline allocations and expose binding snapshots
This commit is contained in:
@@ -75,7 +75,7 @@ namespace ShrinkEventBus
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public virtual ShrinkPostResult Post<TEvent>(in TEvent eventData) where TEvent : IShrinkEvent
|
||||
{
|
||||
if (eventData is null)
|
||||
if (!typeof(TEvent).IsValueType && eventData is null)
|
||||
throw new ArgumentNullException(nameof(eventData));
|
||||
if (Volatile.Read(ref _disposed) != 0)
|
||||
return TraceWithoutDispatch(in eventData,
|
||||
@@ -84,6 +84,11 @@ namespace ShrinkEventBus
|
||||
if (_isInline || _scheduler.IsOnSchedulerThread)
|
||||
return Dispatch(in eventData);
|
||||
|
||||
return PostScheduled(in eventData);
|
||||
}
|
||||
|
||||
private ShrinkPostResult PostScheduled<TEvent>(in TEvent eventData) where TEvent : IShrinkEvent
|
||||
{
|
||||
var queuedEvent = eventData;
|
||||
if (_scheduler.TryPost(() => Dispatch(in queuedEvent)))
|
||||
return new ShrinkPostResult(true, false, false);
|
||||
@@ -94,7 +99,7 @@ namespace ShrinkEventBus
|
||||
public virtual UniTask<ShrinkPostResult> PostAsync<TEvent>(TEvent eventData,
|
||||
CancellationToken cancellationToken = default) where TEvent : IShrinkEvent
|
||||
{
|
||||
if (eventData is null)
|
||||
if (!typeof(TEvent).IsValueType && eventData is null)
|
||||
throw new ArgumentNullException(nameof(eventData));
|
||||
if (Volatile.Read(ref _disposed) != 0)
|
||||
return UniTask.FromResult(TraceWithoutDispatch(in eventData,
|
||||
@@ -168,6 +173,13 @@ namespace ShrinkEventBus
|
||||
return new EventSubscription(this, subscriptionId);
|
||||
}
|
||||
|
||||
internal IReadOnlyList<(Type EventType, System.Reflection.MethodInfo Handler)> CaptureBindings()
|
||||
{
|
||||
var bindings = new List<(Type, System.Reflection.MethodInfo)>();
|
||||
lock (_channelGate) foreach (var channel in _channels.Values) channel.CaptureBindings(bindings);
|
||||
return bindings;
|
||||
}
|
||||
|
||||
internal int SubscriberCount
|
||||
{
|
||||
get
|
||||
@@ -367,7 +379,7 @@ namespace ShrinkEventBus
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override ShrinkPostResult Post<TEvent>(in TEvent eventData)
|
||||
{
|
||||
if (eventData is null)
|
||||
if (!typeof(TEvent).IsValueType && eventData is null)
|
||||
throw new ArgumentNullException(nameof(eventData));
|
||||
if (IsDisposed)
|
||||
return TraceWithoutDispatch(in eventData,
|
||||
@@ -378,7 +390,7 @@ namespace ShrinkEventBus
|
||||
public override UniTask<ShrinkPostResult> PostAsync<TEvent>(TEvent eventData,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (eventData is null)
|
||||
if (!typeof(TEvent).IsValueType && eventData is null)
|
||||
throw new ArgumentNullException(nameof(eventData));
|
||||
if (IsDisposed)
|
||||
return UniTask.FromResult(TraceWithoutDispatch(in eventData,
|
||||
|
||||
Reference in New Issue
Block a user