Skip to content

Commit

Permalink
Merge pull request #403 from stonstad/Contributions
Browse files Browse the repository at this point in the history
Remove CustomUpdateData heap allocation in OnUpdate hot path.
  • Loading branch information
DarthAffe authored Nov 3, 2024
2 parents a26eaf9 + da51871 commit 71f1115
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions RGB.NET.Core/Update/AbstractUpdateTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public abstract class AbstractUpdateTrigger : AbstractBindable, IUpdateTrigger
/// Invokes the <see cref="Starting"/>-event.
/// </summary>
/// <param name="updateData">Optional custom-data passed to the subscribers of the <see cref="Starting"/>.event.</param>
protected virtual void OnStartup(CustomUpdateData? updateData = null) => Starting?.Invoke(this, updateData ?? new CustomUpdateData());
protected virtual void OnStartup(CustomUpdateData? updateData = null) => Starting?.Invoke(this, updateData ?? CustomUpdateData.Empty);

/// <summary>
/// Invokes the <see cref="Update"/>-event.
/// </summary>
/// <param name="updateData">Optional custom-data passed to the subscribers of the <see cref="Update"/>.event.</param>
protected virtual void OnUpdate(CustomUpdateData? updateData = null) => Update?.Invoke(this, updateData ?? new CustomUpdateData());
protected virtual void OnUpdate(CustomUpdateData? updateData = null) => Update?.Invoke(this, updateData ?? CustomUpdateData.Empty);

/// <inheritdoc />
public abstract void Start();
Expand Down
3 changes: 3 additions & 0 deletions RGB.NET.Core/Update/CustomUpdateData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public sealed class CustomUpdateData : ICustomUpdateData
{
#region Properties & Fields

// ReSharper disable once InconsistentNaming
public static readonly CustomUpdateData Empty = new();

private readonly Dictionary<string, object?> _data = [];

#endregion
Expand Down

0 comments on commit 71f1115

Please sign in to comment.