mirror of
https://github.com/google/uuid.git
synced 2024-11-24 08:32:23 +02:00
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
This commit is contained in:
parent
47f5b3936c
commit
cd5fbbdd02
12
uuid.go
12
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 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 {
|
||||
uuidStrs[i] = uuid.String()
|
||||
}
|
||||
return uuidStrs
|
||||
}
|
||||
|
15
uuid_test.go
15
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 := UUIDs{uuid1, uuid2}
|
||||
for i := 0; i < b.N; i++ {
|
||||
uuids.Strings()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user