From 4d29c8608f5391a8b7032a621d12e8146aedab54 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Thu, 18 May 2017 12:05:29 +0200 Subject: [PATCH] Avoid strings.Join which is expensive --- pkg/proxy/iptables/proxier.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index faee0d34f83..1eb90c5f8bb 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -1543,7 +1543,15 @@ func (proxier *Proxier) clearUDPConntrackForPort(port int) { // Join all words with spaces, terminate with newline and write to buf. func writeLine(buf *bytes.Buffer, words ...string) { - buf.WriteString(strings.Join(words, " ") + "\n") + // We avoid strings.Join for performance reasons. + for i := range words { + buf.WriteString(words[i]) + if i < len(words)-1 { + buf.WriteByte(' ') + } else { + buf.WriteByte('\n') + } + } } func isLocalIP(ip string) (bool, error) {