From f73b5595633d828823cdbe263e56f9c931c6c817 Mon Sep 17 00:00:00 2001 From: xlf <1396510465@qq.com> Date: Mon, 23 Sep 2024 16:11:15 +0800 Subject: [PATCH] Optimize Map2Kvs functions by pre-allocating memory --- client/dtmgrpc/dtmgimp/utils.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/dtmgrpc/dtmgimp/utils.go b/client/dtmgrpc/dtmgimp/utils.go index 2bb6ba5..a41aa40 100644 --- a/client/dtmgrpc/dtmgimp/utils.go +++ b/client/dtmgrpc/dtmgimp/utils.go @@ -7,14 +7,14 @@ package dtmgimp import ( - context "context" + "context" "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "github.com/dtm-labs/logger" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" - emptypb "google.golang.org/protobuf/types/known/emptypb" + "google.golang.org/protobuf/types/known/emptypb" ) // MustProtoMarshal must version of proto.Marshal @@ -77,7 +77,7 @@ func TransInfo2Ctx(ctx context.Context, gid, transType, branchID, op, dtm string // Map2Kvs map to metadata kv func Map2Kvs(m map[string]string) []string { - kvs := []string{} + kvs := make([]string, 0, len(m)<<1) for k, v := range m { kvs = append(kvs, k, v) }