Passes the index by reference so we can control the allocation.

This commit is contained in:
James Phillips 2016-08-12 14:51:50 -07:00
parent f7fcb03004
commit 17c10d78bc
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
2 changed files with 6 additions and 6 deletions

View File

@ -494,18 +494,16 @@ func (d *DNSServer) formatNodeRecord(node *structs.Node, addr, qName string, qTy
return records
}
// indexRRs creates a map which indexes a given list of RRs by name. NOTE that
// indexRRs populates a map which indexes a given list of RRs by name. NOTE that
// the names are all squashed to lower case so we can perform case-insensitive
// lookups; the RRs are not modified.
func indexRRs(rrs []dns.RR) map[string]dns.RR {
index := make(map[string]dns.RR, len(rrs))
func indexRRs(rrs []dns.RR, index map[string]dns.RR) {
for _, rr := range rrs {
name := strings.ToLower(rr.Header().Name)
if _, ok := index[name]; !ok {
index[name] = rr
}
}
return index
}
// syncExtra takes a DNS response message and sets the extra data to the most
@ -557,7 +555,8 @@ func trimUDPResponse(config *DNSConfig, resp *dns.Msg) (trimmed bool) {
// extra data when necessary.
var index map[string]dns.RR
if hasExtra {
index = indexRRs(resp.Extra)
index = make(map[string]dns.RR, len(resp.Extra))
indexRRs(resp.Extra, index)
}
// This cuts UDP responses to a useful but limited number of responses.

View File

@ -3522,7 +3522,8 @@ func TestDNS_syncExtra(t *testing.T) {
},
}
index := indexRRs(resp.Extra)
index := make(map[string]dns.RR)
indexRRs(resp.Extra, index)
syncExtra(index, resp)
expected := &dns.Msg{