Avoid unnecessary string allocations

This commit is contained in:
flan
2018-02-08 03:18:33 +01:00
parent 238ffa4270
commit 8a6d09f9c3

View File

@@ -196,8 +196,8 @@ func (b *Birc) Send(msg config.Message) (string, error) {
} }
for _, text := range strings.Split(msg.Text, "\n") { for _, text := range strings.Split(msg.Text, "\n") {
if len(text) > b.Config.MessageLength { if len(text) > b.Config.MessageLength {
for len(text)+len(" <message clipped>") > b.Config.MessageLength { text = text[:b.Config.MessageLength-len(" <message clipped>")]
_, size := utf8.DecodeLastRuneInString(text) if r, size := utf8.DecodeLastRuneInString(text); r == utf8.RuneError {
text = text[:len(text)-size] text = text[:len(text)-size]
} }
text += " <message clipped>" text += " <message clipped>"