Skip to content

Commit cd5fbbd

Browse files
authoredOct 26, 2023
feat: UUIDs slice type with Strings() convenience method (#133)
* feat: add uuid slice type with strings convenience method * test: benchmark new UUIDs.Strings() feature * docs: improve comments on UUIDs * fix: typos in UUIDs strings benchmark
1 parent 47f5b39 commit cd5fbbd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
 

‎uuid.go

+12
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,15 @@ func DisableRandPool() {
294294
poolMu.Lock()
295295
poolPos = randPoolSize
296296
}
297+
298+
// UUIDs is a slice of UUID types.
299+
type UUIDs []UUID
300+
301+
// Strings returns a string slice containing the string form of each UUID in uuids.
302+
func (uuids UUIDs) Strings() []string {
303+
var uuidStrs = make([]string, len(uuids))
304+
for i, uuid := range uuids {
305+
uuidStrs[i] = uuid.String()
306+
}
307+
return uuidStrs
308+
}

‎uuid_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,18 @@ func BenchmarkUUID_NewPooled(b *testing.B) {
733733
}
734734
})
735735
}
736+
737+
func BenchmarkUUIDs_Strings(b *testing.B) {
738+
uuid1, err := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
739+
if err != nil {
740+
b.Fatal(err)
741+
}
742+
uuid2, err := Parse("7d444840-9dc0-11d1-b245-5ffdce74fad2")
743+
if err != nil {
744+
b.Fatal(err)
745+
}
746+
uuids := UUIDs{uuid1, uuid2}
747+
for i := 0; i < b.N; i++ {
748+
uuids.Strings()
749+
}
750+
}

0 commit comments

Comments
 (0)
Please sign in to comment.