perf: avoid string concatenation in loops (#7572)

* perf: avoid string concatenation in loops

Apply perfpsrint linter

Signed-off-by: Philippe Antoine <contact@catenacyber.fr>

* ci: enable perfsprint

Signed-off-by: Philippe Antoine <contact@catenacyber.fr>

---------

Signed-off-by: Philippe Antoine <contact@catenacyber.fr>
This commit is contained in:
Catena cyber
2025-10-06 09:05:58 +02:00
committed by GitHub
parent 51f94b0bb4
commit 625f6c9307
8 changed files with 36 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"regexp"
"sort"
"strings"
"github.com/coredns/coredns/plugin/pkg/dnsutil"
)
@@ -22,8 +23,6 @@ func checkZoneSyntax(zone string) bool {
// grpc://example.com.:1055
// example.com.:1053 on 127.0.0.1
func startUpZones(protocol, addr string, zones map[string][]*Config) string {
s := ""
keys := make([]string, len(zones))
i := 0
@@ -33,25 +32,26 @@ func startUpZones(protocol, addr string, zones map[string][]*Config) string {
}
sort.Strings(keys)
var sb strings.Builder
for _, zone := range keys {
if !checkZoneSyntax(zone) {
s += fmt.Sprintf("Warning: Domain %q does not follow RFC1035 preferred syntax\n", zone)
sb.WriteString(fmt.Sprintf("Warning: Domain %q does not follow RFC1035 preferred syntax\n", zone))
}
// split addr into protocol, IP and Port
_, ip, port, err := SplitProtocolHostPort(addr)
if err != nil {
// this should not happen, but we need to take care of it anyway
s += fmt.Sprintln(protocol + zone + ":" + addr)
sb.WriteString(fmt.Sprintln(protocol + zone + ":" + addr))
continue
}
if ip == "" {
s += fmt.Sprintln(protocol + zone + ":" + port)
sb.WriteString(fmt.Sprintln(protocol + zone + ":" + port))
continue
}
// if the server is listening on a specific address let's make it visible in the log,
// so one can differentiate between all active listeners
s += fmt.Sprintln(protocol + zone + ":" + port + " on " + ip)
sb.WriteString(fmt.Sprintln(protocol + zone + ":" + port + " on " + ip))
}
return s
return sb.String()
}