Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gen_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func Enum(fd protoreflect.FieldDescriptor, opts GenOptions) protoreflect.EnumNumber {
constraints := getFieldConstraints(fd, opts)
allEnumValues := fd.Enum().Values()
allowedValues := []protoreflect.EnumNumber{}
allowedValues := make([]protoreflect.EnumNumber, 0, allEnumValues.Len())

if allEnumValues.Len() > 0 {
for i := 0; i < allEnumValues.Len(); i++ {
Expand Down
21 changes: 21 additions & 0 deletions gen_enum_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fauxrpc_test

import (
"testing"

"github.com/brianvoe/gofakeit/v7"
"github.com/sudorandom/fauxrpc"
testv1 "github.com/sudorandom/fauxrpc/private/gen/test/v1"
"google.golang.org/protobuf/reflect/protoreflect"
)

func BenchmarkEnumFunction(b *testing.B) {
md := testv1.File_test_v1_test_proto.Messages().ByName("EnumTest")
fd := md.Fields().ByName(protoreflect.Name("enum_in"))
opts := fauxrpc.GenOptions{MaxDepth: 3, Faker: gofakeit.New(0)}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = fauxrpc.Enum(fd, opts)
}
}