devicescale: Cache scale values

This commit is contained in:
Hajime Hoshi 2019-03-12 01:31:11 +09:00
parent a3882dbc37
commit 1392129e41

View File

@ -18,12 +18,22 @@ import (
"sync"
)
type pos struct {
x, y int
}
var (
m sync.Mutex
m sync.Mutex
cache = map[pos]float64{}
)
func GetAt(x, y int) float64 {
m.Lock()
defer m.Unlock()
return impl(x, y)
if s, ok := cache[pos{x, y}]; ok {
return s
}
s := impl(x, y)
cache[pos{x, y}] = s
return s
}