1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00

DeviceVisualizer - reduce allocations

This commit is contained in:
Diogo Trindade 2023-06-06 12:00:05 +01:00
parent 70b6035b0d
commit 06e6075c4d

View File

@ -120,23 +120,26 @@ public class DeviceVisualizer : Control
if (Device == null)
return false;
Color[] state = new Color[Device.RgbDevice.Count()];
bool difference = _previousState.Length != state.Length;
bool difference = false;
int newLedCount = Device.RgbDevice.Count();
if (_previousState.Length != newLedCount)
{
_previousState = new Color[newLedCount];
difference = true;
}
// Check all LEDs for differences and copy the colors to a new state
int index = 0;
foreach (Led led in Device.RgbDevice)
{
if (!difference && !led.Color.Equals(_previousState[index]))
if (_previousState[index] != led.Color)
difference = true;
state[index] = led.Color;
_previousState[index] = led.Color;
index++;
}
// Store the new state for next time
_previousState = state;
return difference;
}