msg.Service: optimize a bit (#2374)

Make the NewSRV and friends slightly smarter. Optimize the calling of
targetStrip which is almost certainly not used.

Added benchmark show a modest improvement:

benchmark             old ns/op     new ns/op     delta
BenchmarkNewSRV-4     300           283           -5.67%

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2018-12-07 20:09:09 +00:00
committed by Yong Tang
parent 16197a1add
commit 8a5eb58bc0
2 changed files with 21 additions and 8 deletions

View File

@@ -123,3 +123,11 @@ func TestGroup(t *testing.T) {
t.Fatalf("Failure to group seventh set: %v", sx)
}
}
func BenchmarkNewSRV(b *testing.B) {
s := &Service{Host: "www,example.org", Port: 8080}
for n := 0; n < b.N; n++ {
srv := s.NewSRV("www.example.org.", 16)
srv = srv
}
}