From f18664df2d4c50e00e27d7e5953e4f837f7da285 Mon Sep 17 00:00:00 2001 From: Dylan Bargteil Date: Wed, 25 Oct 2023 11:35:02 -0400 Subject: [PATCH 1/4] feat: add uuid slice type with strings convenience method --- uuid.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/uuid.go b/uuid.go index a56138c..f371561 100644 --- a/uuid.go +++ b/uuid.go @@ -294,3 +294,15 @@ func DisableRandPool() { poolMu.Lock() poolPos = randPoolSize } + +// UUIDs is a slice of UUID types +type UUIDs []UUID + +// Strings returns a slice of the string form of each UUID in the received slice of UUIDs +func (uuids UUIDs) Strings() []string { + var uuidStrs = make([]string, len(uuids)) + for i, uuid := range uuids { + uuidStrs[i] = uuid.String() + } + return uuidStrs +} From 59e2a6b808382a4514ab00bbf958a7aa1ff51495 Mon Sep 17 00:00:00 2001 From: Dylan Bargteil Date: Wed, 25 Oct 2023 11:35:23 -0400 Subject: [PATCH 2/4] test: benchmark new UUIDs.Strings() feature --- uuid_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/uuid_test.go b/uuid_test.go index 429ac7a..30228cd 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -733,3 +733,18 @@ func BenchmarkUUID_NewPooled(b *testing.B) { } }) } + +func BenchmarkUUIDs_Strings(b *testing.B) { + uuid1, err := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479") + if err != nil { + b.Fatal(err) + } + uuid2, err := Parse("7d444840-9dc0-11d1-b245-5ffdce74fad2") + if err != nil { + b.Fatal(err) + } + uuids := uuid.UUIDs{uuid1, uuid2} + for i := 0; i < b.N; i++ { + uuid.Strings() + } +} From 997a025b6ae86f9fba8ef51429cca0c044f13040 Mon Sep 17 00:00:00 2001 From: Dylan Bargteil Date: Wed, 25 Oct 2023 11:53:01 -0400 Subject: [PATCH 3/4] docs: improve comments on UUIDs --- uuid.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uuid.go b/uuid.go index f371561..c6ec380 100644 --- a/uuid.go +++ b/uuid.go @@ -295,10 +295,10 @@ func DisableRandPool() { poolPos = randPoolSize } -// UUIDs is a slice of UUID types +// UUIDs is a slice of UUID types. type UUIDs []UUID -// Strings returns a slice of the string form of each UUID in the received slice of UUIDs +// Strings returns a string slice containing the string form of each UUID in uuids. func (uuids UUIDs) Strings() []string { var uuidStrs = make([]string, len(uuids)) for i, uuid := range uuids { From 3ba161c62bcd458b738ef429e576ee0e944be0d2 Mon Sep 17 00:00:00 2001 From: Dylan Bargteil Date: Wed, 25 Oct 2023 12:59:44 -0400 Subject: [PATCH 4/4] fix: typos in UUIDs strings benchmark --- uuid_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uuid_test.go b/uuid_test.go index 30228cd..6f22e8a 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -743,8 +743,8 @@ func BenchmarkUUIDs_Strings(b *testing.B) { if err != nil { b.Fatal(err) } - uuids := uuid.UUIDs{uuid1, uuid2} + uuids := UUIDs{uuid1, uuid2} for i := 0; i < b.N; i++ { - uuid.Strings() + uuids.Strings() } }