refactor(tracker): change so that all icon initialization is a lazy & cache in iconcache

This commit is contained in:
vsariola
2021-02-01 17:57:13 +02:00
parent c667ffb4e1
commit 3cf2fc70a8
4 changed files with 30 additions and 48 deletions

22
tracker/iconcache.go Normal file
View File

@ -0,0 +1,22 @@
package tracker
import (
"log"
"gioui.org/widget"
)
var iconCache = map[*byte]*widget.Icon{}
// widgetForIcon returns a widget for IconVG data, but caching the results
func widgetForIcon(icon []byte) *widget.Icon {
if widget, ok := iconCache[&icon[0]]; ok {
return widget
}
widget, err := widget.NewIcon(icon)
if err != nil {
log.Fatal(err)
}
iconCache[&icon[0]] = widget
return widget
}