Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small performance things #391

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions RGB.NET.Core/Extensions/MathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions RGB.NET.Core/Rendering/Textures/PixelTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public PixelTexture(int with, int height, int dataPerPixel, ISampler<T> sampler,
/// </summary>
/// <param name="pixel">The pixel-data to convert.</param>
/// <returns>The color represented by the specified pixel-data.</returns>
protected abstract Color GetColor(in ReadOnlySpan<T> pixel);
protected abstract Color GetColor(ReadOnlySpan<T> pixel);

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

/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override Color GetColor(in ReadOnlySpan<Color> pixel) => pixel[0];
protected override Color GetColor(ReadOnlySpan<Color> pixel) => pixel[0];

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class AverageColorSampler : ISampler<Color>
#region Methods

/// <inheritdoc />
public unsafe void Sample(in SamplerInfo<Color> info, in Span<Color> pixelData)
public unsafe void Sample(in SamplerInfo<Color> info, Span<Color> pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return;
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Core/Rendering/Textures/Sampler/ISampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface ISampler<T>
/// </summary>
/// <param name="info">The information containing the data to sample.</param>
/// <param name="pixelData">The buffer used to write the resulting pixel to.</param>
void Sample(in SamplerInfo<T> info, in Span<T> pixelData);
void Sample(in SamplerInfo<T> info, Span<T> pixelData);
}
2 changes: 1 addition & 1 deletion RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public readonly ref struct SamplerInfo<T>
/// <param name="width">The width of the region the data comes from.</param>
/// <param name="height">The height of region the data comes from.</param>
/// <param name="data">The data to sample.</param>
public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, in ReadOnlySpan<T> data)
public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, ReadOnlySpan<T> data)
{
this._x = x;
this._y = y;
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Core/Update/Devices/UpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected virtual void OnStartup(object? sender, CustomUpdateData customData) {
/// Performs the update this queue is responsible for.
/// </summary>
/// <param name="dataSet">The set of data that needs to be updated.</param>
protected abstract bool Update(in ReadOnlySpan<(TIdentifier key, TData color)> dataSet);
protected abstract bool Update(ReadOnlySpan<(TIdentifier key, TData color)> dataSet);

/// <summary>
/// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available.
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger, IAuraSyncDevice devic
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public CoolerMasterUpdateQueue(IDeviceUpdateTrigger updateTrigger, CoolerMasterD
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, _CorsairDe
#region Methods

/// <inheritdoc />
protected override unsafe bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override unsafe bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIn
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData)
}

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LogitechPerDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public LogitechZoneUpdateQueue(IDeviceUpdateTrigger updateTrigger, LogitechDevic
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MsiDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string deviceTyp
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId, Open
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public PicoPiBulkUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk,
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PicoPiHIDUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, i
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
6 changes: 3 additions & 3 deletions RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private int GetVersion()
/// </summary>
/// <param name="data">The data to send.</param>
/// <param name="channel">The channel to update.</param>
public void SendHidUpdate(in Span<byte> buffer, int channel)
public void SendHidUpdate(Span<byte> buffer, int channel)
{
int chunks = buffer.Length / HID_OFFSET_MULTIPLIER;
if ((chunks * HID_OFFSET_MULTIPLIER) < buffer.Length) chunks++;
Expand All @@ -232,7 +232,7 @@ public void SendHidUpdate(in Span<byte> buffer, int channel)
/// <param name="channel">The channel to update.</param>
/// <param name="chunk">The chunk id of the packet. (Required if packets are fragmented.)</param>
/// <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>
public void SendHidUpdate(in Span<byte> data, int channel, int chunk, bool update)
public void SendHidUpdate(Span<byte> data, int channel, int chunk, bool update)
{
if (data.Length == 0) return;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RazerChromaLinkUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
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];

Expand Down
4 changes: 2 additions & 2 deletions RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

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

#endregion
}
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RazerHeadsetUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
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];

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
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];

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
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];

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RazerMouseUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
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];

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RazerMousepadUpdateQueue(IDeviceUpdateTrigger updateTrigger)
#region Methods

/// <inheritdoc />
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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData)
}

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.WLED/Generic/WLedDeviceUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData)
}

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override void OnStartup(object? sender, CustomUpdateData customData)
}

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected override void OnStartup(object? sender, CustomUpdateData customData)
}

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public WootingUpdateQueue(IDeviceUpdateTrigger updateTrigger, byte deviceId)
#region Methods

/// <inheritdoc />
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Presets/Textures/BytePixelTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public BytePixelTexture(int with, int height, byte[] data, ISampler<byte> sample

/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override Color GetColor(in ReadOnlySpan<byte> pixel)
protected override Color GetColor(ReadOnlySpan<byte> pixel)
{
return ColorFormat switch
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Presets/Textures/FloatPixelTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public FloatPixelTexture(int with, int height, float[] data, ISampler<float> sam

/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override Color GetColor(in ReadOnlySpan<float> pixel)
protected override Color GetColor(ReadOnlySpan<float> pixel)
{
return ColorFormat switch
{
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class AverageByteSampler : ISampler<byte>
#region Methods

/// <inheritdoc />
public unsafe void Sample(in SamplerInfo<byte> info, in Span<byte> pixelData)
public unsafe void Sample(in SamplerInfo<byte> info, Span<byte> pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return;
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class AverageFloatSampler : ISampler<float>
#region Methods

/// <inheritdoc />
public unsafe void Sample(in SamplerInfo<float> info, in Span<float> pixelData)
public unsafe void Sample(in SamplerInfo<float> info, Span<float> pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return;
Expand Down
Loading