mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
internal/affine: further optimization to avoid heap allocation
Updates #2119
This commit is contained in:
parent
d518e64e22
commit
5cdd2f8bce
@ -552,7 +552,20 @@ func (c colorMImplScale) Concat(other ColorM) ColorM {
|
|||||||
|
|
||||||
var lhsb [16]float32
|
var lhsb [16]float32
|
||||||
var lhst [4]float32
|
var lhst [4]float32
|
||||||
other.Elements(&lhsb, &lhst)
|
|
||||||
|
// Calling a method of an interface type escapes arguments to heap (#2119).
|
||||||
|
// Instead, cast `other` to a concrete type and call `Elements` functions of it.
|
||||||
|
switch other := other.(type) {
|
||||||
|
case ColorMIdentity:
|
||||||
|
other.Elements(&lhsb, &lhst)
|
||||||
|
case colorMImplScale:
|
||||||
|
other.Elements(&lhsb, &lhst)
|
||||||
|
case *colorMImplBodyTranslate:
|
||||||
|
other.Elements(&lhsb, &lhst)
|
||||||
|
default:
|
||||||
|
panic("affine: unexpected ColorM implementation")
|
||||||
|
}
|
||||||
|
|
||||||
s := &c.scale
|
s := &c.scale
|
||||||
return &colorMImplBodyTranslate{
|
return &colorMImplBodyTranslate{
|
||||||
body: [...]float32{
|
body: [...]float32{
|
||||||
@ -572,7 +585,20 @@ func (c *colorMImplBodyTranslate) Concat(other ColorM) ColorM {
|
|||||||
|
|
||||||
var lhsb [16]float32
|
var lhsb [16]float32
|
||||||
var lhst [4]float32
|
var lhst [4]float32
|
||||||
other.Elements(&lhsb, &lhst)
|
|
||||||
|
// Calling a method of an interface type escapes arguments to heap (#2119).
|
||||||
|
// Instead, cast `other` to a concrete type and call `Elements` functions of it.
|
||||||
|
switch other := other.(type) {
|
||||||
|
case ColorMIdentity:
|
||||||
|
other.Elements(&lhsb, &lhst)
|
||||||
|
case colorMImplScale:
|
||||||
|
other.Elements(&lhsb, &lhst)
|
||||||
|
case *colorMImplBodyTranslate:
|
||||||
|
other.Elements(&lhsb, &lhst)
|
||||||
|
default:
|
||||||
|
panic("affine: unexpected ColorM implementation")
|
||||||
|
}
|
||||||
|
|
||||||
rhsb := &c.body
|
rhsb := &c.body
|
||||||
rhst := &c.translate
|
rhst := &c.translate
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user