Eliminate roBs allocation from packDomainName
This allocation only occurred when s was escaped, but will no longer occur.
This commit is contained in:
parent
07ed56b1d6
commit
f522504216
26
msg.go
26
msg.go
|
@ -214,8 +214,6 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
|
||||||
var (
|
var (
|
||||||
begin int
|
begin int
|
||||||
bs []byte
|
bs []byte
|
||||||
roBs = s
|
|
||||||
bsDirty bool
|
|
||||||
wasDot bool
|
wasDot bool
|
||||||
)
|
)
|
||||||
loop:
|
loop:
|
||||||
|
@ -247,7 +245,6 @@ loop:
|
||||||
ls--
|
ls--
|
||||||
}
|
}
|
||||||
|
|
||||||
bsDirty = true
|
|
||||||
wasDot = false
|
wasDot = false
|
||||||
case '.':
|
case '.':
|
||||||
if wasDot {
|
if wasDot {
|
||||||
|
@ -267,16 +264,21 @@ loop:
|
||||||
return lenmsg, labels, ErrBuf
|
return lenmsg, labels, ErrBuf
|
||||||
}
|
}
|
||||||
|
|
||||||
if compression != nil && bsDirty {
|
|
||||||
roBs = string(bs[:ls])
|
|
||||||
bsDirty = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't try to compress '.'
|
// Don't try to compress '.'
|
||||||
// We should only compress when compress is true, but we should also still pick
|
// We should only compress when compress is true, but we should also still pick
|
||||||
// up names that can be used for *future* compression(s).
|
// up names that can be used for *future* compression(s).
|
||||||
if compression != nil && !isRootLabel(s, bs, begin, ls) {
|
if compression != nil && !isRootLabel(s, bs, begin, ls) {
|
||||||
if p, ok := compression[roBs[begin:]]; ok {
|
var (
|
||||||
|
p int
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
if bs == nil {
|
||||||
|
p, ok = compression[s[begin:]]
|
||||||
|
} else {
|
||||||
|
p, ok = compression[string(bs[begin:ls])]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
// The first hit is the longest matching dname
|
// The first hit is the longest matching dname
|
||||||
// keep the pointer offset we get back and store
|
// keep the pointer offset we get back and store
|
||||||
// the offset of the current name, because that's
|
// the offset of the current name, because that's
|
||||||
|
@ -289,7 +291,11 @@ loop:
|
||||||
}
|
}
|
||||||
} else if off < maxCompressionOffset {
|
} else if off < maxCompressionOffset {
|
||||||
// Only offsets smaller than maxCompressionOffset can be used.
|
// Only offsets smaller than maxCompressionOffset can be used.
|
||||||
compression[roBs[begin:]] = off
|
if bs == nil {
|
||||||
|
compression[s[begin:]] = off
|
||||||
|
} else {
|
||||||
|
compression[string(bs[begin:ls])] = off
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue