From c6e7a834679b85a464b2f1617280f600d0fdf61c Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 5 Jun 2017 20:12:35 -0500 Subject: [PATCH] Reduce copying in fillPolygon A slice of points means copying every point into the slice, then copying every point's data from the slice to TrianglesData. An array of indicies lets the compiler make better choices. --- imdraw/imdraw.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/imdraw/imdraw.go b/imdraw/imdraw.go index 0d40452..e5a8c95 100644 --- a/imdraw/imdraw.go +++ b/imdraw/imdraw.go @@ -354,11 +354,12 @@ func (imd *IMDraw) fillPolygon() { imd.tri.SetLen(imd.tri.Len() + 3*(len(points)-2)) for i, j := 1, off; i+1 < len(points); i, j = i+1, j+3 { - for k, p := range []point{points[0], points[i], points[i+1]} { - (*imd.tri)[j+k].Position = p.pos - (*imd.tri)[j+k].Color = p.col - (*imd.tri)[j+k].Picture = p.pic - (*imd.tri)[j+k].Intensity = p.in + for k, p := range []int{0, i, i + 1} { + tri := &(*imd.tri)[j+k] + tri.Position = points[p].pos + tri.Color = points[p].col + tri.Picture = points[p].pic + tri.Intensity = points[p].in } }