Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: UUIDs slice type with Strings() convenience method #133

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,15 @@ func DisableRandPool() {
poolMu.Lock()
poolPos = randPoolSize
}

// UUIDs is a slice of UUID types.
type UUIDs []UUID
bormanp marked this conversation as resolved.
Show resolved Hide resolved

// 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 changes: 15 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,18 @@
}
})
}

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}

Check failure on line 746 in uuid_test.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.x)

undefined: uuid

Check failure on line 746 in uuid_test.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.21)

uuids declared and not used

Check failure on line 746 in uuid_test.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.21)

undefined: uuid
for i := 0; i < b.N; i++ {
uuid.Strings()

Check failure on line 748 in uuid_test.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.x)

undefined: uuid

Check failure on line 748 in uuid_test.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.21)

undefined: uuid
}
}