mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-07-05 13:53:25 +00:00
fix: reduce limitedString memory cost
(cherry picked from commit 5b0c693aba
)
This commit is contained in:
24
coolq/api.go
24
coolq/api.go
@ -4,10 +4,6 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/client"
|
||||
"github.com/Mrs4s/MiraiGo/message"
|
||||
"github.com/tidwall/gjson"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
@ -17,9 +13,16 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/client"
|
||||
"github.com/Mrs4s/MiraiGo/message"
|
||||
"github.com/Mrs4s/MiraiGo/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Version go-cqhttp的版本信息,在编译时使用ldflags进行覆盖
|
||||
@ -1354,10 +1357,15 @@ func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) MSG {
|
||||
}
|
||||
|
||||
func limitedString(str string) string {
|
||||
if strings.Count(str, "") <= 10 {
|
||||
if utf8.RuneCountInString(str) <= 10 {
|
||||
return str
|
||||
}
|
||||
limited := []rune(str)
|
||||
limited = limited[:10]
|
||||
b := utils.S2B(str)
|
||||
limited := make([]rune, 0, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
decodeRune, size := utf8.DecodeRune(b)
|
||||
b = b[size:]
|
||||
limited = append(limited, decodeRune)
|
||||
}
|
||||
return string(limited) + " ..."
|
||||
}
|
||||
|
Reference in New Issue
Block a user