Skip to content

Commit a1c6c97

Browse files
committed
fix(lint): avoid string concat in loop
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
1 parent 9919c7b commit a1c6c97

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

internal/dns/dns.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,10 @@ func randomFallbackServer() string {
552552
}
553553

554554
func formatMessageAnswerSection(section []dns.RR) string {
555-
ret := "[ "
555+
var ret strings.Builder
556+
ret.WriteString("[ ")
556557
for idx, rr := range section {
557-
ret += fmt.Sprintf(
558+
ret.WriteString(fmt.Sprintf(
558559
"< %s >",
559560
strings.ReplaceAll(
560561
strings.TrimPrefix(
@@ -564,20 +565,21 @@ func formatMessageAnswerSection(section []dns.RR) string {
564565
"\t",
565566
" ",
566567
),
567-
)
568+
))
568569
if idx != len(section)-1 {
569-
ret += `,`
570+
ret.WriteString(`,`)
570571
}
571-
ret += ` `
572+
ret.WriteString(` `)
572573
}
573-
ret += "]"
574-
return ret
574+
ret.WriteString("]")
575+
return ret.String()
575576
}
576577

577578
func formatMessageQuestionSection(section []dns.Question) string {
578-
ret := "[ "
579+
var ret strings.Builder
580+
ret.WriteString("[ ")
579581
for idx, question := range section {
580-
ret += fmt.Sprintf(
582+
ret.WriteString(fmt.Sprintf(
581583
"< %s >",
582584
strings.ReplaceAll(
583585
strings.TrimPrefix(
@@ -587,12 +589,12 @@ func formatMessageQuestionSection(section []dns.Question) string {
587589
"\t",
588590
" ",
589591
),
590-
)
592+
))
591593
if idx != len(section)-1 {
592-
ret += `,`
594+
ret.WriteString(`,`)
593595
}
594-
ret += ` `
596+
ret.WriteString(` `)
595597
}
596-
ret += "]"
597-
return ret
598+
ret.WriteString("]")
599+
return ret.String()
598600
}

internal/handshake/domain.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"fmt"
1414
"io"
1515
"net"
16+
"strings"
1617
)
1718

1819
const (
@@ -297,6 +298,7 @@ func domainRecordNameDecode(r *BytesReader) (string, error) {
297298
if c > DnsMaxLabel {
298299
return "", errors.New("label too long")
299300
}
301+
var sb strings.Builder
300302
for range int(c) {
301303
b, err := r.ReadByte()
302304
if err != nil {
@@ -311,8 +313,9 @@ func domainRecordNameDecode(r *BytesReader) (string, error) {
311313
if b == 0x2e {
312314
b = 0xfe
313315
}
314-
name += string([]byte{b})
316+
sb.WriteString(string([]byte{b}))
315317
}
318+
name += sb.String()
316319
if len(name) > 0 {
317320
name += "."
318321
}

0 commit comments

Comments
 (0)