mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Reduced some more allocations
This commit is contained in:
parent
0cf4f39ccf
commit
70ccc4d575
@ -15,6 +15,8 @@ public class ListLedGroup : AbstractLedGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly ActionDisposable _unlockDisposable;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list containing the <see cref="Led"/> of this <see cref="ListLedGroup"/>.
|
||||
/// </summary>
|
||||
@ -31,7 +33,9 @@ public class ListLedGroup : AbstractLedGroup
|
||||
/// <param name="surface">Specifies the surface to attach this group to or <c>null</c> if the group should not be attached on creation.</param>
|
||||
public ListLedGroup(RGBSurface? surface)
|
||||
: base(surface)
|
||||
{ }
|
||||
{
|
||||
_unlockDisposable = new ActionDisposable(Unlock);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
@ -42,6 +46,8 @@ public class ListLedGroup : AbstractLedGroup
|
||||
public ListLedGroup(RGBSurface? surface, IEnumerable<Led> leds)
|
||||
: base(surface)
|
||||
{
|
||||
_unlockDisposable = new ActionDisposable(Unlock);
|
||||
|
||||
AddLeds(leds);
|
||||
}
|
||||
|
||||
@ -54,6 +60,8 @@ public class ListLedGroup : AbstractLedGroup
|
||||
public ListLedGroup(RGBSurface? surface, params Led[] leds)
|
||||
: base(surface)
|
||||
{
|
||||
_unlockDisposable = new ActionDisposable(Unlock);
|
||||
|
||||
AddLeds(leds);
|
||||
}
|
||||
|
||||
@ -141,8 +149,10 @@ public class ListLedGroup : AbstractLedGroup
|
||||
{
|
||||
Monitor.Enter(GroupLeds);
|
||||
leds = GroupLeds;
|
||||
return new ActionDisposable(() => Monitor.Exit(GroupLeds));
|
||||
return _unlockDisposable;
|
||||
}
|
||||
|
||||
private void Unlock() => Monitor.Exit(GroupLeds);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -157,11 +157,13 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
|
||||
using (TimerHelper.RequestHighResolutionTimer())
|
||||
while (!UpdateToken.IsCancellationRequested)
|
||||
if (HasDataEvent.WaitOne(Timeout))
|
||||
LastUpdateTime = TimerHelper.Execute(() => OnUpdate(), UpdateFrequency * 1000);
|
||||
LastUpdateTime = TimerHelper.Execute(TimerExecute, UpdateFrequency * 1000);
|
||||
else if ((HeartbeatTimer > 0) && (LastUpdateTimestamp > 0) && (TimerHelper.GetElapsedTime(LastUpdateTimestamp) > HeartbeatTimer))
|
||||
OnUpdate(new CustomUpdateData().Heartbeat());
|
||||
}
|
||||
|
||||
private void TimerExecute() => OnUpdate();
|
||||
|
||||
protected override void OnUpdate(CustomUpdateData? updateData = null)
|
||||
{
|
||||
base.OnUpdate(updateData);
|
||||
|
||||
@ -83,12 +83,12 @@ public sealed class ManualUpdateTrigger : AbstractUpdateTrigger
|
||||
OnStartup();
|
||||
|
||||
while (!UpdateToken.IsCancellationRequested)
|
||||
{
|
||||
if (_mutex.WaitOne(100))
|
||||
LastUpdateTime = TimerHelper.Execute(() => OnUpdate(_customUpdateData));
|
||||
}
|
||||
LastUpdateTime = TimerHelper.Execute(TimerExecute);
|
||||
}
|
||||
|
||||
private void TimerExecute() => OnUpdate(_customUpdateData);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose() => Stop();
|
||||
|
||||
|
||||
@ -131,10 +131,11 @@ public class TimerUpdateTrigger : AbstractUpdateTrigger
|
||||
|
||||
using (TimerHelper.RequestHighResolutionTimer())
|
||||
while (!UpdateToken.IsCancellationRequested)
|
||||
LastUpdateTime = TimerHelper.Execute(() => OnUpdate(_customUpdateData), UpdateFrequency * 1000);
|
||||
|
||||
LastUpdateTime = TimerHelper.Execute(TimerExecute, UpdateFrequency * 1000);
|
||||
}
|
||||
|
||||
private void TimerExecute() => OnUpdate(_customUpdateData);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
@ -121,7 +122,7 @@ public class RectangleLedGroup : AbstractLedGroup
|
||||
/// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Presets.Groups.RectangleLedGroup" />.
|
||||
/// </summary>
|
||||
/// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Presets.Groups.RectangleLedGroup" />.</returns>
|
||||
public override IList<Led> ToList() => _ledCache ??= (Surface?.Leds.Where(led => led.AbsoluteBoundary.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? new List<Led>());
|
||||
public override IList<Led> ToList() => _ledCache ??= ((IList<Led>?)Surface?.Leds.Where(led => led.AbsoluteBoundary.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? Array.Empty<Led>());
|
||||
|
||||
private void InvalidateCache() => _ledCache = null;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user