From f1f17ffdbc4f43defc857db305019214db201a8d Mon Sep 17 00:00:00 2001 From: Michael Haro Date: Mon, 23 Feb 2015 23:11:31 -0800 Subject: [PATCH] Split Copy into Copy and CopyTo. CopyTo allows bypassing allocating a new Msg to work towards less allocation GC churn. --- msg.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/msg.go b/msg.go index 209e63ed..0b63e986 100644 --- a/msg.go +++ b/msg.go @@ -1915,7 +1915,11 @@ func Copy(r RR) RR { // Copy returns a new *Msg which is a deep-copy of dns. func (dns *Msg) Copy() *Msg { - r1 := new(Msg) + return dns.CopyTo(new(Msg)) +} + +// CopyTo copies the contents to the provided message using a deep-copy and returns the copy. +func (dns *Msg) CopyTo(r1 *Msg) *Msg { r1.MsgHdr = dns.MsgHdr r1.Compress = dns.Compress