Avoid strings.Join which is expensive

This commit is contained in:
Wojciech Tyczynski 2017-05-18 12:05:29 +02:00
parent 5464c39333
commit 4d29c8608f

View File

@ -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) {