kube-proxy/ipvs/ipset: preallocate ListEntries result with bound capacity

ListEntries' result slice is bounded by the number of lines parsed from
the ipset output (`len(strs)`). Pass that as the make() capacity so
the slice doesn't need to be regrown as entries are appended.

No behavior change.
This commit is contained in:
alexmchughdev
2026-05-06 20:04:58 +01:00
parent 43fe7b4250
commit 9727de2d9d

View File

@@ -401,7 +401,7 @@ func (runner *runner) ListEntries(set string) ([]string, error) {
memberMatcher := regexp.MustCompile(EntryMemberPattern)
list := memberMatcher.ReplaceAllString(string(out[:]), "")
strs := strings.Split(list, "\n")
results := make([]string, 0)
results := make([]string, 0, len(strs))
for i := range strs {
if len(strs[i]) > 0 {
results = append(results, strs[i])