mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Reduce defer sentences for performance
This commit is contained in:
parent
0ab46b1780
commit
a816c9c7fe
@ -49,13 +49,14 @@ func (q *commandQueue) appendVertices(vertices []float32) {
|
||||
}
|
||||
|
||||
func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, clr *affine.ColorM, mode opengl.CompositeMode) {
|
||||
// Avoid defer for performance
|
||||
q.m.Lock()
|
||||
defer q.m.Unlock()
|
||||
q.appendVertices(vertices)
|
||||
if 0 < len(q.commands) {
|
||||
if c, ok := q.commands[len(q.commands)-1].(*drawImageCommand); ok {
|
||||
if c.isMergeable(dst, src, clr, mode) {
|
||||
c.verticesNum += len(vertices)
|
||||
q.m.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -68,12 +69,13 @@ func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float
|
||||
mode: mode,
|
||||
}
|
||||
q.commands = append(q.commands, c)
|
||||
q.m.Unlock()
|
||||
}
|
||||
|
||||
func (q *commandQueue) Enqueue(command command) {
|
||||
q.m.Lock()
|
||||
defer q.m.Unlock()
|
||||
q.commands = append(q.commands, command)
|
||||
q.m.Unlock()
|
||||
}
|
||||
|
||||
// commandGroups separates q.commands into some groups.
|
||||
|
@ -66,19 +66,22 @@ func (i *images) resolveStalePixels(context *opengl.Context) error {
|
||||
}
|
||||
|
||||
func (i *images) resetPixelsIfDependingOn(target *Image) {
|
||||
// Avoid defer for performance
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
if target == nil {
|
||||
// disposed
|
||||
i.m.Unlock()
|
||||
return
|
||||
}
|
||||
if i.lastChecked == target {
|
||||
i.m.Unlock()
|
||||
return
|
||||
}
|
||||
i.lastChecked = target
|
||||
for img := range i.images {
|
||||
img.makeStaleIfDependingOn(target)
|
||||
}
|
||||
i.m.Unlock()
|
||||
}
|
||||
|
||||
func (i *images) restore(context *opengl.Context) error {
|
||||
|
Loading…
Reference in New Issue
Block a user