From 42e5b0564c11ebc17df709b1503a98a0ad095786 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Mon, 22 Feb 2021 16:36:24 +0800 Subject: [PATCH] =?UTF-8?q?fast=EF=BC=81=EF=BC=81=EF=BC=81=20goos:=20windo?= =?UTF-8?q?ws=20goarch:=20amd64=20pkg:=20github.com/Mrs4s/go-cqhttp/coolq?= =?UTF-8?q?=20cpu:=20Intel(R)=20Core(TM)=20i5-9300H=20CPU=20@=202.40GHz=20?= =?UTF-8?q?BenchmarkCQBot=5FConvertStringMessage-8=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20963939=20=20=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?1205=20ns/op=20=20=20=20=20=20=20=20=20=20=20=20=20368=20B/op?= =?UTF-8?q?=20=20=20=20=20=20=20=20=2011=20allocs/op=20PASS=20ok=20=20=20?= =?UTF-8?q?=20=20=20github.com/Mrs4s/go-cqhttp/coolq=20=20=20=20=20=20=20?= =?UTF-8?q?=201.764s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/cqcode.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index ba77f27..40ce439 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -359,7 +359,7 @@ func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r st // ConvertStringMessage 将消息字符串转为消息元素数组 func (bot *CQBot) ConvertStringMessage(s string, isGroup bool) (r []message.IMessageElement) { var t, key string - var d map[string]string + var d = map[string]string{} ptr := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&s)).Data) l := len(s) i, j, CQBegin := 0, 0, 0 @@ -448,7 +448,9 @@ S1: // Plain Text } goto End S2: // CQCode Type - d = make(map[string]string) + for k := range d { // 内存复用,减小GC压力 + delete(d, k) + } for ; i < l; i++ { switch *(*byte)(add(ptr, uintptr(i))) { case ',': // CQ Code with params