From ee5d49dbd39f7313f805cd14221d53d80fbd31ea Mon Sep 17 00:00:00 2001 From: Seebs Date: Fri, 9 Jun 2017 22:22:27 -0500 Subject: [PATCH] Push: Don't convert pixel.RGBA to pixel.RGBA Because that's expensive, even in the case where the conversion is trivial. Use type assertion first. Reduces runtime cost of imdraw.Push from ~15.3% to 8.4%, so not-quite-50% of runtime cost of pushing points. If you were setting imd.Color to Color objects that aren't RGBA every single point, not much help. But if you set it and then draw a bunch of points, this will be a big win. --- imdraw/imdraw.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imdraw/imdraw.go b/imdraw/imdraw.go index 7f72a4d..e616c39 100644 --- a/imdraw/imdraw.go +++ b/imdraw/imdraw.go @@ -128,7 +128,9 @@ func (imd *IMDraw) Draw(t pixel.Target) { // Push adds some points to the IM queue. All Pushed points will have the same properties except for // the position. func (imd *IMDraw) Push(pts ...pixel.Vec) { - imd.Color = pixel.ToRGBA(imd.Color) + if _, ok := imd.Color.(pixel.RGBA); !ok { + imd.Color = pixel.ToRGBA(imd.Color) + } opts := point{ col: imd.Color.(pixel.RGBA), pic: imd.Picture,