mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
DeviceVisualizer - reduce allocations
This commit is contained in:
parent
70b6035b0d
commit
06e6075c4d
@ -120,23 +120,26 @@ public class DeviceVisualizer : Control
|
|||||||
if (Device == null)
|
if (Device == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Color[] state = new Color[Device.RgbDevice.Count()];
|
bool difference = false;
|
||||||
bool difference = _previousState.Length != state.Length;
|
|
||||||
|
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
|
// Check all LEDs for differences and copy the colors to a new state
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (Led led in Device.RgbDevice)
|
foreach (Led led in Device.RgbDevice)
|
||||||
{
|
{
|
||||||
if (!difference && !led.Color.Equals(_previousState[index]))
|
if (_previousState[index] != led.Color)
|
||||||
difference = true;
|
difference = true;
|
||||||
|
|
||||||
state[index] = led.Color;
|
_previousState[index] = led.Color;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the new state for next time
|
|
||||||
_previousState = state;
|
|
||||||
|
|
||||||
return difference;
|
return difference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user