From f21acbd7673c4fc71e0ce49c387d054922b5badc Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 22 Jun 2024 19:48:52 +0200 Subject: [PATCH 1/2] Fixed potential performance issue with for-loops when Spans are passed by reference --- RGB.NET.Core/Rendering/Textures/PixelTexture.cs | 4 ++-- .../Rendering/Textures/Sampler/AverageColorSampler.cs | 2 +- RGB.NET.Core/Rendering/Textures/Sampler/ISampler.cs | 2 +- RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs | 2 +- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 2 +- RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs | 2 +- .../Generic/CoolerMasterUpdateQueue.cs | 2 +- RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs | 2 +- .../Generic/CorsairDeviceUpdateQueue.cs | 2 +- RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs | 2 +- RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs | 2 +- .../PerDevice/LogitechPerDeviceUpdateQueue.cs | 2 +- .../PerKey/LogitechPerKeyUpdateQueue.cs | 2 +- RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs | 2 +- RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs | 2 +- RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs | 2 +- RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs | 2 +- RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs | 2 +- RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs | 2 +- RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs | 6 +++--- .../ChromaLink/RazerChromaLinkUpdateQueue.cs | 2 +- RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs | 4 ++-- RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs | 2 +- RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs | 2 +- RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs | 2 +- RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs | 2 +- RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs | 2 +- .../Generic/SteelSeriesDeviceUpdateQueue.cs | 2 +- RGB.NET.Devices.WLED/Generic/WLedDeviceUpdateQueue.cs | 2 +- RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs | 2 +- .../NodeMCU/NodeMCUWS2812USBUpdateQueue.cs | 2 +- RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs | 2 +- RGB.NET.Presets/Textures/BytePixelTexture.cs | 2 +- RGB.NET.Presets/Textures/FloatPixelTexture.cs | 2 +- RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs | 2 +- RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs | 2 +- 36 files changed, 40 insertions(+), 40 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index 170d2d55..5ad4459b 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -126,7 +126,7 @@ public PixelTexture(int with, int height, int dataPerPixel, ISampler sampler, /// /// The pixel-data to convert. /// The color represented by the specified pixel-data. - protected abstract Color GetColor(in ReadOnlySpan pixel); + protected abstract Color GetColor(ReadOnlySpan pixel); /// /// Gets the pixel-data at the specified location. @@ -189,7 +189,7 @@ public PixelTexture(int with, int height, Color[] data, ISampler sampler) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected override Color GetColor(in ReadOnlySpan pixel) => pixel[0]; + protected override Color GetColor(ReadOnlySpan pixel) => pixel[0]; #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs index 9ba2cb02..f7e3258b 100644 --- a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs +++ b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs @@ -22,7 +22,7 @@ public sealed class AverageColorSampler : ISampler #region Methods /// - public unsafe void Sample(in SamplerInfo info, in Span pixelData) + public unsafe void Sample(in SamplerInfo info, Span pixelData) { int count = info.Width * info.Height; if (count == 0) return; diff --git a/RGB.NET.Core/Rendering/Textures/Sampler/ISampler.cs b/RGB.NET.Core/Rendering/Textures/Sampler/ISampler.cs index 9a2c4f10..04fcfa08 100644 --- a/RGB.NET.Core/Rendering/Textures/Sampler/ISampler.cs +++ b/RGB.NET.Core/Rendering/Textures/Sampler/ISampler.cs @@ -13,5 +13,5 @@ public interface ISampler /// /// The information containing the data to sample. /// The buffer used to write the resulting pixel to. - void Sample(in SamplerInfo info, in Span pixelData); + void Sample(in SamplerInfo info, Span pixelData); } \ No newline at end of file diff --git a/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs b/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs index bf59c937..19ae76ce 100644 --- a/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs +++ b/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs @@ -44,7 +44,7 @@ public readonly ref struct SamplerInfo /// The width of the region the data comes from. /// The height of region the data comes from. /// The data to sample. - public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, in ReadOnlySpan data) + public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, ReadOnlySpan data) { this._x = x; this._y = y; diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 22ef7f9e..7db35177 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -80,7 +80,7 @@ protected virtual void OnStartup(object? sender, CustomUpdateData customData) { /// Performs the update this queue is responsible for. /// /// The set of data that needs to be updated. - protected abstract bool Update(in ReadOnlySpan<(TIdentifier key, TData color)> dataSet); + protected abstract bool Update(ReadOnlySpan<(TIdentifier key, TData color)> dataSet); /// /// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available. diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 2f40ec68..e6077a68 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -43,7 +43,7 @@ public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger, IAuraSyncDevice devic #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs index 99e14281..f7506cec 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs @@ -37,7 +37,7 @@ public CoolerMasterUpdateQueue(IDeviceUpdateTrigger updateTrigger, CoolerMasterD #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index be3a3bf7..bd707a2a 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -40,7 +40,7 @@ internal CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, _CorsairDe #region Methods /// - protected override unsafe bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override unsafe bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs index a7669117..52373532 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs @@ -35,7 +35,7 @@ public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIn #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs index 2e513ec4..4fb1f433 100644 --- a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs +++ b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs @@ -59,7 +59,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData) } /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs index df86acca..e228ea5d 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs @@ -7,7 +7,7 @@ internal sealed class DebugDeviceUpdateQueue() : UpdateQueue(new DeviceUpdateTri { #region Methods - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true; + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) => true; #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs index b780a283..655c9a71 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs @@ -25,7 +25,7 @@ public LogitechPerDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs index 7f1917f2..7159b66e 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs @@ -24,7 +24,7 @@ public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs index c9a83a56..baf22535 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs @@ -33,7 +33,7 @@ public LogitechZoneUpdateQueue(IDeviceUpdateTrigger updateTrigger, LogitechDevic #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs index 0367029b..0a648569 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs @@ -34,7 +34,7 @@ public MsiDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string deviceTyp #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs index 945c4ff5..4cc8929b 100644 --- a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs @@ -35,7 +35,7 @@ protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId) #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs index 0537d11b..43ddc0ba 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs @@ -48,7 +48,7 @@ public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId, Open #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs index edd290be..3b211ae0 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs @@ -44,7 +44,7 @@ public PicoPiBulkUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs index 652ba807..cae4080b 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs @@ -41,7 +41,7 @@ public PicoPiHIDUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, i #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs index 2dcd6de4..1e5c3ce2 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs @@ -212,7 +212,7 @@ private int GetVersion() /// /// The data to send. /// The channel to update. - public void SendHidUpdate(in Span buffer, int channel) + public void SendHidUpdate(Span buffer, int channel) { int chunks = buffer.Length / HID_OFFSET_MULTIPLIER; if ((chunks * HID_OFFSET_MULTIPLIER) < buffer.Length) chunks++; @@ -232,7 +232,7 @@ public void SendHidUpdate(in Span buffer, int channel) /// The channel to update. /// The chunk id of the packet. (Required if packets are fragmented.) /// A value indicating if the device should update directly after receiving this packet. (If packets are fragmented this should only be true for the last chunk.) - public void SendHidUpdate(in Span data, int channel, int chunk, bool update) + public void SendHidUpdate(Span data, int channel, int chunk, bool update) { if (data.Length == 0) return; @@ -253,7 +253,7 @@ public void SendHidUpdate(in Span data, int channel, int chunk, bool updat /// /// The data packet to send. /// The channel to update. - public void SendBulkUpdate(in Span data, int channel) + public void SendBulkUpdate(Span data, int channel) { if ((data.Length == 0) || !IsBulkSupported) return; diff --git a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs index 17b7add5..1b12a93a 100644 --- a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerChromaLinkUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS]; diff --git a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs index 615e48b1..f8fa4170 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs @@ -30,7 +30,7 @@ protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -77,7 +77,7 @@ public override void Reset() /// /// The data to be updated. /// An pointing to the effect parameter struct. - protected abstract nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet); + protected abstract nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs index 8ddbce31..e29f435f 100644 --- a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerHeadsetUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS]; diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs index 68e0f5f7..4a709aa5 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS]; diff --git a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs index 7e2470e1..e33487aa 100644 --- a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS]; diff --git a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs index cbdde12b..8e056c61 100644 --- a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerMouseUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS]; diff --git a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs index 8f510e43..3b694878 100644 --- a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerMousepadUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS]; diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs index c85f3946..815e223d 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs @@ -51,7 +51,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData) } /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.WLED/Generic/WLedDeviceUpdateQueue.cs b/RGB.NET.Devices.WLED/Generic/WLedDeviceUpdateQueue.cs index d16834b5..7ebeef73 100644 --- a/RGB.NET.Devices.WLED/Generic/WLedDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.WLED/Generic/WLedDeviceUpdateQueue.cs @@ -63,7 +63,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData) } /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs index f1aa16c8..699218d0 100644 --- a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs @@ -56,7 +56,7 @@ protected override void OnStartup(object? sender, CustomUpdateData customData) } /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs index 38a51f1a..442c5b38 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -77,7 +77,7 @@ protected override void OnStartup(object? sender, CustomUpdateData customData) } /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs index 8a3012eb..be942cf6 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs @@ -33,7 +33,7 @@ public WootingUpdateQueue(IDeviceUpdateTrigger updateTrigger, byte deviceId) #region Methods /// - protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { diff --git a/RGB.NET.Presets/Textures/BytePixelTexture.cs b/RGB.NET.Presets/Textures/BytePixelTexture.cs index 103b2ae9..176b54fa 100644 --- a/RGB.NET.Presets/Textures/BytePixelTexture.cs +++ b/RGB.NET.Presets/Textures/BytePixelTexture.cs @@ -61,7 +61,7 @@ public BytePixelTexture(int with, int height, byte[] data, ISampler sample /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected override Color GetColor(in ReadOnlySpan pixel) + protected override Color GetColor(ReadOnlySpan pixel) { return ColorFormat switch { diff --git a/RGB.NET.Presets/Textures/FloatPixelTexture.cs b/RGB.NET.Presets/Textures/FloatPixelTexture.cs index f60b1778..4657ec3f 100644 --- a/RGB.NET.Presets/Textures/FloatPixelTexture.cs +++ b/RGB.NET.Presets/Textures/FloatPixelTexture.cs @@ -61,7 +61,7 @@ public FloatPixelTexture(int with, int height, float[] data, ISampler sam /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected override Color GetColor(in ReadOnlySpan pixel) + protected override Color GetColor(ReadOnlySpan pixel) { return ColorFormat switch { diff --git a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs index bf5d7c6b..f9002c9b 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs @@ -18,7 +18,7 @@ public sealed class AverageByteSampler : ISampler #region Methods /// - public unsafe void Sample(in SamplerInfo info, in Span pixelData) + public unsafe void Sample(in SamplerInfo info, Span pixelData) { int count = info.Width * info.Height; if (count == 0) return; diff --git a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs index cea8f451..9cdc37b1 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs @@ -12,7 +12,7 @@ public sealed class AverageFloatSampler : ISampler #region Methods /// - public unsafe void Sample(in SamplerInfo info, in Span pixelData) + public unsafe void Sample(in SamplerInfo info, Span pixelData) { int count = info.Width * info.Height; if (count == 0) return; From 6f0711564c44e4b667637cf9e0ef51b3246c36e8 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 22 Jun 2024 19:49:38 +0200 Subject: [PATCH 2/2] Removed unnecessary in GetByteValueFromPercentage --- RGB.NET.Core/Extensions/MathExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RGB.NET.Core/Extensions/MathExtensions.cs b/RGB.NET.Core/Extensions/MathExtensions.cs index c3176b1a..665df6a3 100644 --- a/RGB.NET.Core/Extensions/MathExtensions.cs +++ b/RGB.NET.Core/Extensions/MathExtensions.cs @@ -91,9 +91,8 @@ public static float Wrap(this float value, float min, float max) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte GetByteValueFromPercentage(this float percentage) { - if (float.IsNaN(percentage)) return 0; + if (float.IsNaN(percentage) || (percentage <= 0)) return 0; - percentage = percentage.Clamp(0, 1.0f); return (byte)(percentage >= 1.0f ? 255 : percentage * 256.0f); }