From acddfed2b1540873cd746f9f2ae3bafdbc4f8e36 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 8 May 2023 20:47:47 +0200 Subject: [PATCH] Removed allocation when applying decorators --- RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs b/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs index 553e53b..bc39b5d 100644 --- a/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs +++ b/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs @@ -74,9 +74,13 @@ public abstract class AbstractBrush : AbstractDecoratable, IBru if (Decorators.Count == 0) return; lock (Decorators) - foreach (IBrushDecorator decorator in Decorators) + // ReSharper disable once ForCanBeConvertedToForeach - Sadly this does not get optimized reliably and causes allocations if foreached + for (int i = 0; i < Decorators.Count; i++) + { + IBrushDecorator decorator = Decorators[i]; if (decorator.IsEnabled) decorator.ManipulateColor(rectangle, renderTarget, ref color); + } } ///