Avoid unnecessary string allocations
This commit is contained in:
@@ -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>"
|
||||||
|
|||||||
Reference in New Issue
Block a user