Skip to content

Commit 41a1d5d

Browse files
authored
Merge pull request #391 from DarthAffe/SmallPerformanceThings
Small performance things
2 parents da2c2a6 + 6f07115 commit 41a1d5d

File tree

37 files changed

+41
-42
lines changed

37 files changed

+41
-42
lines changed

RGB.NET.Core/Extensions/MathExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ public static float Wrap(this float value, float min, float max)
9191
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9292
public static byte GetByteValueFromPercentage(this float percentage)
9393
{
94-
if (float.IsNaN(percentage)) return 0;
94+
if (float.IsNaN(percentage) || (percentage <= 0)) return 0;
9595

96-
percentage = percentage.Clamp(0, 1.0f);
9796
return (byte)(percentage >= 1.0f ? 255 : percentage * 256.0f);
9897
}
9998

RGB.NET.Core/Rendering/Textures/PixelTexture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public PixelTexture(int with, int height, int dataPerPixel, ISampler<T> sampler,
126126
/// </summary>
127127
/// <param name="pixel">The pixel-data to convert.</param>
128128
/// <returns>The color represented by the specified pixel-data.</returns>
129-
protected abstract Color GetColor(in ReadOnlySpan<T> pixel);
129+
protected abstract Color GetColor(ReadOnlySpan<T> pixel);
130130

131131
/// <summary>
132132
/// Gets the pixel-data at the specified location.
@@ -189,7 +189,7 @@ public PixelTexture(int with, int height, Color[] data, ISampler<Color> sampler)
189189

190190
/// <inheritdoc />
191191
[MethodImpl(MethodImplOptions.AggressiveInlining)]
192-
protected override Color GetColor(in ReadOnlySpan<Color> pixel) => pixel[0];
192+
protected override Color GetColor(ReadOnlySpan<Color> pixel) => pixel[0];
193193

194194
#endregion
195195
}

RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed class AverageColorSampler : ISampler<Color>
2222
#region Methods
2323

2424
/// <inheritdoc />
25-
public unsafe void Sample(in SamplerInfo<Color> info, in Span<Color> pixelData)
25+
public unsafe void Sample(in SamplerInfo<Color> info, Span<Color> pixelData)
2626
{
2727
int count = info.Width * info.Height;
2828
if (count == 0) return;

RGB.NET.Core/Rendering/Textures/Sampler/ISampler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ public interface ISampler<T>
1313
/// </summary>
1414
/// <param name="info">The information containing the data to sample.</param>
1515
/// <param name="pixelData">The buffer used to write the resulting pixel to.</param>
16-
void Sample(in SamplerInfo<T> info, in Span<T> pixelData);
16+
void Sample(in SamplerInfo<T> info, Span<T> pixelData);
1717
}

RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public readonly ref struct SamplerInfo<T>
4444
/// <param name="width">The width of the region the data comes from.</param>
4545
/// <param name="height">The height of region the data comes from.</param>
4646
/// <param name="data">The data to sample.</param>
47-
public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, in ReadOnlySpan<T> data)
47+
public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, ReadOnlySpan<T> data)
4848
{
4949
this._x = x;
5050
this._y = y;

RGB.NET.Core/Update/Devices/UpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected virtual void OnStartup(object? sender, CustomUpdateData customData) {
8080
/// Performs the update this queue is responsible for.
8181
/// </summary>
8282
/// <param name="dataSet">The set of data that needs to be updated.</param>
83-
protected abstract bool Update(in ReadOnlySpan<(TIdentifier key, TData color)> dataSet);
83+
protected abstract bool Update(ReadOnlySpan<(TIdentifier key, TData color)> dataSet);
8484

8585
/// <summary>
8686
/// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available.

RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger, IAuraSyncDevice devic
4343
#region Methods
4444

4545
/// <inheritdoc />
46-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
46+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
4747
{
4848
try
4949
{

RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public CoolerMasterUpdateQueue(IDeviceUpdateTrigger updateTrigger, CoolerMasterD
3737
#region Methods
3838

3939
/// <inheritdoc />
40-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
40+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
4141
{
4242
try
4343
{

RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, _CorsairDe
4040
#region Methods
4141

4242
/// <inheritdoc />
43-
protected override unsafe bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
43+
protected override unsafe bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
4444
{
4545
try
4646
{

RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIn
3535
#region Methods
3636

3737
/// <inheritdoc />
38-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
38+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
3939
{
4040
try
4141
{

RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData)
5959
}
6060

6161
/// <inheritdoc />
62-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
62+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
6363
{
6464
try
6565
{

RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal sealed class DebugDeviceUpdateQueue() : UpdateQueue(new DeviceUpdateTri
77
{
88
#region Methods
99

10-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true;
10+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) => true;
1111

1212
#endregion
1313
}

RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public LogitechPerDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2525
#region Methods
2626

2727
/// <inheritdoc />
28-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
28+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
2929
{
3030
try
3131
{

RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2424
#region Methods
2525

2626
/// <inheritdoc />
27-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
27+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
2828
{
2929
try
3030
{

RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public LogitechZoneUpdateQueue(IDeviceUpdateTrigger updateTrigger, LogitechDevic
3333
#region Methods
3434

3535
/// <inheritdoc />
36-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
36+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
3737
{
3838
try
3939
{

RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public MsiDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string deviceTyp
3434
#region Methods
3535

3636
/// <inheritdoc />
37-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
37+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
3838
{
3939
try
4040
{

RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
3535
#region Methods
3636

3737
/// <inheritdoc />
38-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
38+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
3939
{
4040
try
4141
{

RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId, Open
4848
#region Methods
4949

5050
/// <inheritdoc />
51-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
51+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
5252
{
5353
try
5454
{

RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public PicoPiBulkUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk,
4444
#region Methods
4545

4646
/// <inheritdoc />
47-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
47+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
4848
{
4949
try
5050
{

RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public PicoPiHIDUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, i
4141
#region Methods
4242

4343
/// <inheritdoc />
44-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
44+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
4545
{
4646
try
4747
{

RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private int GetVersion()
212212
/// </summary>
213213
/// <param name="data">The data to send.</param>
214214
/// <param name="channel">The channel to update.</param>
215-
public void SendHidUpdate(in Span<byte> buffer, int channel)
215+
public void SendHidUpdate(Span<byte> buffer, int channel)
216216
{
217217
int chunks = buffer.Length / HID_OFFSET_MULTIPLIER;
218218
if ((chunks * HID_OFFSET_MULTIPLIER) < buffer.Length) chunks++;
@@ -232,7 +232,7 @@ public void SendHidUpdate(in Span<byte> buffer, int channel)
232232
/// <param name="channel">The channel to update.</param>
233233
/// <param name="chunk">The chunk id of the packet. (Required if packets are fragmented.)</param>
234234
/// <param name="update">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.)</param>
235-
public void SendHidUpdate(in Span<byte> data, int channel, int chunk, bool update)
235+
public void SendHidUpdate(Span<byte> data, int channel, int chunk, bool update)
236236
{
237237
if (data.Length == 0) return;
238238

@@ -253,7 +253,7 @@ public void SendHidUpdate(in Span<byte> data, int channel, int chunk, bool updat
253253
/// </remarks>
254254
/// <param name="data">The data packet to send.</param>
255255
/// <param name="channel">The channel to update.</param>
256-
public void SendBulkUpdate(in Span<byte> data, int channel)
256+
public void SendBulkUpdate(Span<byte> data, int channel)
257257
{
258258
if ((data.Length == 0) || !IsBulkSupported) return;
259259

RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RazerChromaLinkUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2525
#region Methods
2626

2727
/// <inheritdoc />
28-
protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
28+
protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet)
2929
{
3030
_Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS];
3131

RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger)
3030
#region Methods
3131

3232
/// <inheritdoc />
33-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
33+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
3434
{
3535
try
3636
{
@@ -77,7 +77,7 @@ public override void Reset()
7777
/// </summary>
7878
/// <param name="dataSet">The data to be updated.</param>
7979
/// <returns>An <see cref="IntPtr"/> pointing to the effect parameter struct.</returns>
80-
protected abstract nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet);
80+
protected abstract nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet);
8181

8282
#endregion
8383
}

RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RazerHeadsetUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2525
#region Methods
2626

2727
/// <inheritdoc />
28-
protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
28+
protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet)
2929
{
3030
_Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS];
3131

RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2525
#region Methods
2626

2727
/// <inheritdoc />
28-
protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
28+
protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet)
2929
{
3030
_Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS];
3131

RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2525
#region Methods
2626

2727
/// <inheritdoc />
28-
protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
28+
protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet)
2929
{
3030
_Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS];
3131

RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RazerMouseUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2525
#region Methods
2626

2727
/// <inheritdoc />
28-
protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
28+
protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet)
2929
{
3030
_Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS];
3131

RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RazerMousepadUpdateQueue(IDeviceUpdateTrigger updateTrigger)
2525
#region Methods
2626

2727
/// <inheritdoc />
28-
protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
28+
protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet)
2929
{
3030
_Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS];
3131

RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData)
5151
}
5252

5353
/// <inheritdoc />
54-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
54+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
5555
{
5656
try
5757
{

RGB.NET.Devices.WLED/Generic/WLedDeviceUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData)
6363
}
6464

6565
/// <inheritdoc />
66-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
66+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
6767
{
6868
try
6969
{

RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected override void OnStartup(object? sender, CustomUpdateData customData)
5656
}
5757

5858
/// <inheritdoc />
59-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
59+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
6060
{
6161
try
6262
{

RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected override void OnStartup(object? sender, CustomUpdateData customData)
7777
}
7878

7979
/// <inheritdoc />
80-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
80+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
8181
{
8282
try
8383
{

RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public WootingUpdateQueue(IDeviceUpdateTrigger updateTrigger, byte deviceId)
3333
#region Methods
3434

3535
/// <inheritdoc />
36-
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
36+
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
3737
{
3838
try
3939
{

RGB.NET.Presets/Textures/BytePixelTexture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public BytePixelTexture(int with, int height, byte[] data, ISampler<byte> sample
6161

6262
/// <inheritdoc />
6363
[MethodImpl(MethodImplOptions.AggressiveInlining)]
64-
protected override Color GetColor(in ReadOnlySpan<byte> pixel)
64+
protected override Color GetColor(ReadOnlySpan<byte> pixel)
6565
{
6666
return ColorFormat switch
6767
{

RGB.NET.Presets/Textures/FloatPixelTexture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public FloatPixelTexture(int with, int height, float[] data, ISampler<float> sam
6161

6262
/// <inheritdoc />
6363
[MethodImpl(MethodImplOptions.AggressiveInlining)]
64-
protected override Color GetColor(in ReadOnlySpan<float> pixel)
64+
protected override Color GetColor(ReadOnlySpan<float> pixel)
6565
{
6666
return ColorFormat switch
6767
{

RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class AverageByteSampler : ISampler<byte>
1818
#region Methods
1919

2020
/// <inheritdoc />
21-
public unsafe void Sample(in SamplerInfo<byte> info, in Span<byte> pixelData)
21+
public unsafe void Sample(in SamplerInfo<byte> info, Span<byte> pixelData)
2222
{
2323
int count = info.Width * info.Height;
2424
if (count == 0) return;

RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class AverageFloatSampler : ISampler<float>
1212
#region Methods
1313

1414
/// <inheritdoc />
15-
public unsafe void Sample(in SamplerInfo<float> info, in Span<float> pixelData)
15+
public unsafe void Sample(in SamplerInfo<float> info, Span<float> pixelData)
1616
{
1717
int count = info.Width * info.Height;
1818
if (count == 0) return;

0 commit comments

Comments
 (0)