Share the message buffer if we have room

This commit is contained in:
Alex Ciuba 2014-01-27 19:45:45 -05:00
parent 008dfb4ee8
commit 17ce0cd52f
1 changed files with 9 additions and 1 deletions

10
msg.go
View File

@ -254,7 +254,15 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
pointer := -1
// Emit sequence of counted strings, chopping at dots.
begin := 0
bs := []byte(s)
// We can share the message buffer because we don't need to look back.
// Keeping close makes tests more sensitive to failure (only 1 byte of room).
var bs []byte
if len(s) < len(msg) {
bs = msg[off+1:]
copy(bs, s)
} else {
bs = []byte(s)
}
ro_bs, bs_fresh := s, true
for i := 0; i < ls; i++ {
if bs[i] == '\\' {