mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +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) {
|
func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, clr *affine.ColorM, mode opengl.CompositeMode) {
|
||||||
|
// Avoid defer for performance
|
||||||
q.m.Lock()
|
q.m.Lock()
|
||||||
defer q.m.Unlock()
|
|
||||||
q.appendVertices(vertices)
|
q.appendVertices(vertices)
|
||||||
if 0 < len(q.commands) {
|
if 0 < len(q.commands) {
|
||||||
if c, ok := q.commands[len(q.commands)-1].(*drawImageCommand); ok {
|
if c, ok := q.commands[len(q.commands)-1].(*drawImageCommand); ok {
|
||||||
if c.isMergeable(dst, src, clr, mode) {
|
if c.isMergeable(dst, src, clr, mode) {
|
||||||
c.verticesNum += len(vertices)
|
c.verticesNum += len(vertices)
|
||||||
|
q.m.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,12 +69,13 @@ func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float
|
|||||||
mode: mode,
|
mode: mode,
|
||||||
}
|
}
|
||||||
q.commands = append(q.commands, c)
|
q.commands = append(q.commands, c)
|
||||||
|
q.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *commandQueue) Enqueue(command command) {
|
func (q *commandQueue) Enqueue(command command) {
|
||||||
q.m.Lock()
|
q.m.Lock()
|
||||||
defer q.m.Unlock()
|
|
||||||
q.commands = append(q.commands, command)
|
q.commands = append(q.commands, command)
|
||||||
|
q.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// commandGroups separates q.commands into some groups.
|
// 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) {
|
func (i *images) resetPixelsIfDependingOn(target *Image) {
|
||||||
|
// Avoid defer for performance
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
|
||||||
if target == nil {
|
if target == nil {
|
||||||
// disposed
|
// disposed
|
||||||
|
i.m.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if i.lastChecked == target {
|
if i.lastChecked == target {
|
||||||
|
i.m.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i.lastChecked = target
|
i.lastChecked = target
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
img.makeStaleIfDependingOn(target)
|
img.makeStaleIfDependingOn(target)
|
||||||
}
|
}
|
||||||
|
i.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) restore(context *opengl.Context) error {
|
func (i *images) restore(context *opengl.Context) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user