From ef6cafa0cb9c03973e84db5a74e6d861df4d988e Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Mon, 12 Oct 2020 22:31:00 -0700 Subject: [PATCH] Use slice for range in Drawer.Dirty(), to improve performance --- drawer.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drawer.go b/drawer.go index 1836266..408f807 100644 --- a/drawer.go +++ b/drawer.go @@ -24,8 +24,9 @@ type Drawer struct { Triangles Triangles Picture Picture - targets map[Target]*drawerTarget - inited bool + targets map[Target]*drawerTarget + allTargets []*drawerTarget + inited bool } type drawerTarget struct { @@ -46,7 +47,7 @@ func (d *Drawer) lazyInit() { func (d *Drawer) Dirty() { d.lazyInit() - for _, t := range d.targets { + for _, t := range d.allTargets { t.clean = false } } @@ -68,6 +69,7 @@ func (d *Drawer) Draw(t Target) { pics: make(map[Picture]TargetPicture), } d.targets[t] = dt + d.allTargets = append(d.allTargets, dt) } if dt.tris == nil {