From 23f9bc312ec1a8dc7bda07024179b83ba267bb52 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 29 Jan 2015 22:26:26 +0100 Subject: [PATCH] Use strings.TrimFunc instead of strings.Trim. The latter is just a wrapper around the former, but creating a function on every call, which requires a memory allocation. --- message.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/message.go b/message.go index 8a5902d..18a5942 100644 --- a/message.go +++ b/message.go @@ -16,11 +16,14 @@ const ( prefixHost byte = 0x40 // Hostname space byte = 0x20 // Separator - cutset string = "\r\n\x20\x00" // Characters to trim from prefixes/messages. - maxLength = 510 // Maximum length is 512 - 2 for the line endings. ) +func cutsetFunc(r rune) bool { + // Characters to trim from prefixes/messages. + return r == '\r' || r == '\n' || r == '\x20' || r == '\x00' +} + // Objects implementing the Sender interface are able to send messages to an IRC server. // // As there might be a message queue, it is possible that Send returns a nil @@ -155,7 +158,7 @@ type Message struct { func ParseMessage(raw string) (m *Message) { // Ignore empty messages. - if raw = strings.Trim(raw, cutset); len(raw) < 2 { + if raw = strings.TrimFunc(raw, cutsetFunc); len(raw) < 2 { return nil }