mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
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:
parent
059bab0b13
commit
7172e98a31
11
input.go
11
input.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user