input: Do not allocate a touch slice if no touches have been made (#587)

Touches() will always allocate a new slice to copy touches into even if no touches are reported, for example on desktop. Adding a simple check makes sure that this unnecessary allocation does not happen.
This commit is contained in:
Evan Leis 2018-04-23 07:52:50 -07:00 committed by Hajime Hoshi
parent 059bab0b13
commit 7172e98a31

View File

@ -122,12 +122,13 @@ type Touch interface {
// Touches returns the current touch states.
//
// Touches returns nil when there are no touches.
// Touches always returns nil on desktops.
func Touches() []Touch {
t := ui.AdjustedTouches()
tt := make([]Touch, len(t))
for i := 0; i < len(tt); i++ {
tt[i] = t[i]
touches := ui.AdjustedTouches()
var copies []Touch
for _, touch := range touches {
copies = append(copies, touch)
}
return tt
return copies
}