Closed
Description
This method always allocates because it returns a slice that escapes to the return value.
If the method were inlineable, the compiler may prove in some cases that the return value does not escape and can be stack allocated.
Currently, the method is a cost of 222; way over the budget of 80.
One attempt to optimize this was:
func (ip Addr) AsSlice() []byte {
ret := ip.As16()
switch ip.z {
case z0:
return nil
case z4:
return ret[12:]
default:
return ret[:]
}
}
However, this is a function cost of 83. Just slightly over the budget.