diff --git a/main.go b/main.go index 9ac4ab6..f4296ff 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "encoding/json" + "github.com/goccy/go-json" "log" "net/http" _ "net/http/pprof" diff --git a/profile005.pb.gz b/profile005.pb.gz new file mode 100644 index 0000000..054b62d Binary files /dev/null and b/profile005.pb.gz differ diff --git a/samples/aloc.go b/samples/aloc.go index ef43286..78a474a 100644 --- a/samples/aloc.go +++ b/samples/aloc.go @@ -1,18 +1,23 @@ package samples -import "fmt" - func Aloc[O any, T []O](obj O, times int) (result T) { + result = make(T, times+1) for i := 0; i <= times; i++ { - result = append(result, obj) + result[i] = obj } - values := make([]any, 0) for _, o := range result { - values = append(values, fmt.Sprintf("%+v\n", o)) + if isError(o) { + result = nil + return + } } - fmt.Println(values...) return } + +func isError(o any) bool { + _, ok := o.(error) + return ok +} diff --git a/samples/aloc_test.go b/samples/aloc_test.go index 3dac0ce..0e468c0 100644 --- a/samples/aloc_test.go +++ b/samples/aloc_test.go @@ -2,6 +2,7 @@ package samples_test import ( "testing" + "errors" "github.com/rafaelhl/profiling-samples/samples" "github.com/stretchr/testify/assert" @@ -12,3 +13,9 @@ func TestAloc(t *testing.T) { assert.Len(t, result, 11) } + +func TestAlocError(t *testing.T) { + result := samples.Aloc(errors.New("test"), 10) + + assert.Len(t, result, 0) +}