diff --git a/Terminal.Gui/Drawing/LineCanvas/LineCanvas.cs b/Terminal.Gui/Drawing/LineCanvas/LineCanvas.cs index 763467096..2be985764 100644 --- a/Terminal.Gui/Drawing/LineCanvas/LineCanvas.cs +++ b/Terminal.Gui/Drawing/LineCanvas/LineCanvas.cs @@ -211,15 +211,23 @@ public class LineCanvas : IDisposable { Dictionary map = new (); + List intersectionsBufferList = []; + // walk through each pixel of the bitmap for (int y = inArea.Y; y < inArea.Y + inArea.Height; y++) { for (int x = inArea.X; x < inArea.X + inArea.Width; x++) { - IntersectionDefinition [] intersects = _lines - .Select (l => l.Intersects (x, y)) - .OfType () // automatically filters nulls and casts - .ToArray (); + intersectionsBufferList.Clear (); + foreach (var line in _lines) + { + if (line.Intersects (x, y) is { } intersect) + { + intersectionsBufferList.Add (intersect); + } + } + // Safe as long as the list is not modified while the span is in use. + ReadOnlySpan intersects = CollectionsMarshal.AsSpan(intersectionsBufferList); Rune? rune = GetRuneForIntersects (intersects);