Move label copying below compression in packDomainName

When the dname is found in the compression map and compress is true,
this copy is as it will simply be overwritten later. This could provide
a very slight speedup.
This commit is contained in:
Tom Thorogood 2018-11-26 14:59:17 +10:30
parent ecef32b31b
commit 8995ae83e3
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
1 changed files with 17 additions and 17 deletions

34
msg.go
View File

@ -254,19 +254,6 @@ loop:
if off+1+(i-begin) > lenmsg {
return lenmsg, labels, ErrBuf
}
if msg != nil {
msg[off] = byte(i - begin)
}
offset := off
off++
if msg != nil {
if bs == nil {
copy(msg[off:], s[begin:i])
} else {
copy(msg[off:], bs[begin:i])
}
}
off += i - begin
if compress && !bsFresh {
roBs = string(bs)
bsFresh = true
@ -283,15 +270,28 @@ loop:
// If compress is true, we're allowed to compress this dname
if compress {
pointer = p // Where to point to
nameoffset = offset // Where to point from
pointer = p // Where to point to
nameoffset = off // Where to point from
break loop
}
} else if offset < maxCompressionOffset {
} else if off < maxCompressionOffset {
// Only offsets smaller than maxCompressionOffset can be used.
compression[roBs[begin:]] = offset
compression[roBs[begin:]] = off
}
}
// The following is covered by the length check above.
if msg != nil {
msg[off] = byte(i - begin)
if bs == nil {
copy(msg[off+1:], s[begin:i])
} else {
copy(msg[off+1:], bs[begin:i])
}
}
off += 1 + i - begin
labels++
begin = i + 1
default: