mirror of
https://github.com/miekg/dns.git
synced 2025-10-16 12:21:00 +02:00
Reduce string allocations
This commit is contained in:
parent
c97bb6d79d
commit
f73d400eb2
12
msg.go
12
msg.go
@ -255,6 +255,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
|
|||||||
// Emit sequence of counted strings, chopping at dots.
|
// Emit sequence of counted strings, chopping at dots.
|
||||||
begin := 0
|
begin := 0
|
||||||
bs := []byte(s)
|
bs := []byte(s)
|
||||||
|
ro_bs, bs_fresh := s, true
|
||||||
for i := 0; i < ls; i++ {
|
for i := 0; i < ls; i++ {
|
||||||
if bs[i] == '\\' {
|
if bs[i] == '\\' {
|
||||||
for j := i; j < ls-1; j++ {
|
for j := i; j < ls-1; j++ {
|
||||||
@ -274,6 +275,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
|
|||||||
}
|
}
|
||||||
ls -= 2
|
ls -= 2
|
||||||
}
|
}
|
||||||
|
bs_fresh = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,12 +306,16 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
|
|||||||
}
|
}
|
||||||
off++
|
off++
|
||||||
}
|
}
|
||||||
|
if compress && !bs_fresh {
|
||||||
|
ro_bs = string(bs)
|
||||||
|
bs_fresh = true
|
||||||
|
}
|
||||||
// Dont try to compress '.'
|
// Dont try to compress '.'
|
||||||
if compression != nil && string(bs[begin:]) != "." {
|
if compress && ro_bs[begin:] != "." {
|
||||||
if p, ok := compression[string(bs[begin:])]; !ok {
|
if p, ok := compression[ro_bs[begin:]]; !ok {
|
||||||
// Only offsets smaller than this can be used.
|
// Only offsets smaller than this can be used.
|
||||||
if offset < maxCompressionOffset {
|
if offset < maxCompressionOffset {
|
||||||
compression[string(bs[begin:])] = offset
|
compression[ro_bs[begin:]] = offset
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The first hit is the longest matching dname
|
// The first hit is the longest matching dname
|
||||||
|
Loading…
x
Reference in New Issue
Block a user