mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
input: Remove unnecessary empty slices
This commit is contained in:
parent
ccb23f1992
commit
92193b2362
@ -26,15 +26,11 @@ func (i *Input) CursorPosition() (x, y int) {
|
|||||||
return i.cursorX, i.cursorY
|
return i.cursorX, i.cursorY
|
||||||
}
|
}
|
||||||
|
|
||||||
var emptyIDs = []int{}
|
|
||||||
|
|
||||||
func (i *Input) GamepadIDs() []int {
|
func (i *Input) GamepadIDs() []int {
|
||||||
i.m.RLock()
|
i.m.RLock()
|
||||||
defer i.m.RUnlock()
|
defer i.m.RUnlock()
|
||||||
if len(i.gamepads) == 0 {
|
if len(i.gamepads) == 0 {
|
||||||
// Avoid creating a slice if possible.
|
return nil
|
||||||
// This is a performance optimization for browsers.
|
|
||||||
return emptyIDs
|
|
||||||
}
|
}
|
||||||
r := []int{}
|
r := []int{}
|
||||||
for id, g := range i.gamepads {
|
for id, g := range i.gamepads {
|
||||||
@ -81,16 +77,12 @@ func (i *Input) IsGamepadButtonPressed(id int, button GamepadButton) bool {
|
|||||||
return i.gamepads[id].buttonPressed[button]
|
return i.gamepads[id].buttonPressed[button]
|
||||||
}
|
}
|
||||||
|
|
||||||
var emptyTouches = []*Touch{}
|
|
||||||
|
|
||||||
func (in *Input) Touches() []*Touch {
|
func (in *Input) Touches() []*Touch {
|
||||||
in.m.RLock()
|
in.m.RLock()
|
||||||
defer in.m.RUnlock()
|
defer in.m.RUnlock()
|
||||||
|
|
||||||
if len(in.touches) == 0 {
|
if len(in.touches) == 0 {
|
||||||
// Avoid creating a slice if possible.
|
return nil
|
||||||
// This is a performance optimization for browsers.
|
|
||||||
return emptyTouches
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t := make([]*Touch, len(in.touches))
|
t := make([]*Touch, len(in.touches))
|
||||||
|
Loading…
Reference in New Issue
Block a user