mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
internal/affine: avoid heap allocations by casting a variable to a concrete type
This is a dirty hack but seems efficient. Closes #2119
This commit is contained in:
parent
f69c550992
commit
ecaa25faba
@ -520,10 +520,21 @@ func (c colorMImplScale) Equals(other ColorM) bool {
|
|||||||
func (c *colorMImplBodyTranslate) Equals(other ColorM) bool {
|
func (c *colorMImplBodyTranslate) Equals(other ColorM) bool {
|
||||||
var lhsb [16]float32
|
var lhsb [16]float32
|
||||||
var lhst [4]float32
|
var lhst [4]float32
|
||||||
other.Elements(&lhsb, &lhst)
|
|
||||||
rhsb := &c.body
|
// Calling a method of an interface type escapes arguments to heap (#2119).
|
||||||
rhst := &c.translate
|
// Instead, cast `other` to a concrete type and call `Elements` functions of it.
|
||||||
return lhsb == *rhsb && lhst == *rhst
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
return lhsb == c.body && lhst == c.translate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ColorMIdentity) Concat(other ColorM) ColorM {
|
func (c ColorMIdentity) Concat(other ColorM) ColorM {
|
||||||
|
Loading…
Reference in New Issue
Block a user