mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
buffered: Use a raw function to avoid allocating structs
This commit is contained in:
parent
fc3e8bebe4
commit
3291ec51bb
@ -18,10 +18,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
|
||||||
f func()
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
delayedCommandsFlushable bool
|
delayedCommandsFlushable bool
|
||||||
|
|
||||||
@ -30,7 +26,7 @@ var (
|
|||||||
// sizes (#879).
|
// sizes (#879).
|
||||||
//
|
//
|
||||||
// TODO: Flush the commands only when necessary (#921).
|
// TODO: Flush the commands only when necessary (#921).
|
||||||
delayedCommands []*command
|
delayedCommands []func()
|
||||||
delayedCommandsM sync.Mutex
|
delayedCommandsM sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,9 +38,7 @@ func makeDelayedCommandFlushable() {
|
|||||||
|
|
||||||
func enqueueDelayedCommand(f func()) {
|
func enqueueDelayedCommand(f func()) {
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
delayedCommands = append(delayedCommands, &command{
|
delayedCommands = append(delayedCommands, f)
|
||||||
f: f,
|
|
||||||
})
|
|
||||||
delayedCommandsM.Unlock()
|
delayedCommandsM.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +51,7 @@ func flushDelayedCommands() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range delayedCommands {
|
for _, c := range delayedCommands {
|
||||||
c.f()
|
c()
|
||||||
}
|
}
|
||||||
delayedCommands = delayedCommands[:0]
|
delayedCommands = delayedCommands[:0]
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user