apns2
apns2 copied to clipboard
Use MarshalJSON directly on notification
Actually on nil notification it panics before as well, so maybe adding nil check to MarshalJSON or on other function may be good, what do you think?
Coverage remained the same at 100.0% when pulling 0094dbad6fcddb57f44732fbd0afeb1183decb49 on moredure:patch-7 into a09d4b5ea2a812939e148b54abb9c2a517aa2411 on sideshow:master.
package main_test
import (
"encoding/json"
"testing"
)
type S struct {
X []byte `json:"x"`
}
func (s *S) MarshalJSON() ([]byte, error) {
return s.X, nil
}
func BenchmarkRun(b *testing.B) {
s := &S{
X: []byte("1"),
}
b.Run("one", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
json.Marshal(s)
}
})
b.Run("one", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
s.MarshalJSON()
}
})
}
BenchmarkRun/one
BenchmarkRun/one-4 5523985 197.8 ns/op 8 B/op 1 allocs/op
BenchmarkRun/one#01
BenchmarkRun/one#01-4 1000000000 0.3392 ns/op 0 B/op 0 allocs/op
At least one additional allocation per payload (leaking param)