1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-26 05:46:10 -04:00

remove unnecessary memory allocation in uuid generation

This commit is contained in:
v2ray 2016-01-12 13:38:47 +01:00
parent 48ff2a5ae8
commit 1958a874cd
2 changed files with 10 additions and 1 deletions

View File

@ -39,8 +39,9 @@ func (this *UUID) Next() *UUID {
md5hash := md5.New()
md5hash.Write(this.Bytes())
md5hash.Write([]byte("16167dc8-16b6-4e6d-b8bb-65dd68113a81"))
newid := new(UUID)
for {
newid, _ := ParseBytes(md5hash.Sum(nil))
md5hash.Sum(newid[:0])
if !newid.Equals(this) {
return newid
}

View File

@ -59,3 +59,11 @@ func TestEquals(t *testing.T) {
assert.Bool(uuid.Equals(uuid2)).IsTrue()
assert.Bool(uuid.Equals(New())).IsFalse()
}
func TestNext(t *testing.T) {
v2testing.Current(t)
uuid := New()
uuid2 := uuid.Next()
assert.Bool(uuid.Equals(uuid2)).IsFalse()
}