mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
remove unnecessary memory allocation in uuid generation
This commit is contained in:
parent
48ff2a5ae8
commit
1958a874cd
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user