Reduce defer sentences for performance

This commit is contained in:
Hajime Hoshi 2017-05-27 21:35:38 +09:00
parent 0ab46b1780
commit a816c9c7fe
2 changed files with 8 additions and 3 deletions

View File

@ -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.

View File

@ -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 {