From f7a152b871cb1c70e4a049954176fd9b345798be Mon Sep 17 00:00:00 2001 From: v2ray Date: Tue, 12 Jan 2016 13:39:02 +0100 Subject: [PATCH] remove unnecessary memory allocation in id generation --- proxy/vmess/id.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/proxy/vmess/id.go b/proxy/vmess/id.go index d40f5b7e..afc51ff1 100644 --- a/proxy/vmess/id.go +++ b/proxy/vmess/id.go @@ -33,18 +33,15 @@ func (this *ID) UUID() *uuid.UUID { return this.uuid } -func NewID(uuid *uuid.UUID) *ID { - md5hash := md5.New() - md5hash.Write(uuid.Bytes()) - md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21")) - cmdKey := md5.Sum(nil) - - return &ID{ - uuid: uuid, - cmdKey: cmdKey, - } -} - func (v ID) CmdKey() []byte { return v.cmdKey[:] } + +func NewID(uuid *uuid.UUID) *ID { + id := &ID{uuid: uuid} + md5hash := md5.New() + md5hash.Write(uuid.Bytes()) + md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21")) + md5.Sum(id.cmdKey[:0]) + return id +}