Skip to content

Commit

Permalink
internal/graphicsdriver/opengl: Avoid allocations by escaping to heap
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Oct 31, 2021
1 parent a3eb893 commit 7661147
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/graphicsdriver/opengl/context_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
case shaderir.Mat4:
gl.UniformMatrix4fv(l, len, false, (*float32)(gl.Ptr(v)))
default:
panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String()))
// Copy shaderir.Type value to avoid heap allocation of typ.
t := typ
panic(fmt.Sprintf("opengl: unexpected type: %s", t.String()))
}
return true
}
Expand Down
4 changes: 3 additions & 1 deletion internal/graphicsdriver/opengl/context_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
case shaderir.Mat4:
c.ctx.UniformMatrix4fv(int32(l), false, v)
default:
panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String()))
// Copy shaderir.Type value to avoid heap allocation of typ.
t := typ
panic(fmt.Sprintf("opengl: unexpected type: %s", t.String()))
}
return true
}
Expand Down

0 comments on commit 7661147

Please sign in to comment.