Split Copy into Copy and CopyTo.

CopyTo allows bypassing allocating a new Msg to work towards less
allocation GC churn.
This commit is contained in:
Michael Haro 2015-02-23 23:11:31 -08:00
parent 0bd3fb7026
commit f1f17ffdbc
1 changed files with 5 additions and 1 deletions

6
msg.go
View File

@ -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