From 4c076221390d18ea8fdeef6cfdaa65a8f1262509 Mon Sep 17 00:00:00 2001 From: Ross Bryan Date: Tue, 27 Feb 2024 21:18:16 -0500 Subject: [PATCH] chore: remove reflection zero type when zero value is known reflection uses unsafe types and is cpu intensive. we can reduce cpu cycles on every api call by simple comparing an empty strings equality to the value of the AuthToken. strings.EqualFold is a std lib solution that provides similar functionality, but that is not necessary for comparing empty strings as it simply uses the standard equality operator as well Topic: rm-reflection Relative: projquay-6620 Signed-off-by: Ross Bryan --- pkg/client/quay/client.go | 4 +--- pkg/utils/utils.go | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pkg/client/quay/client.go b/pkg/client/quay/client.go index c24afb5b..f638e974 100644 --- a/pkg/client/quay/client.go +++ b/pkg/client/quay/client.go @@ -8,8 +8,6 @@ import ( "io/ioutil" "net/http" "net/url" - - "github.com/quay/quay-bridge-operator/pkg/utils" ) type QuayClient struct { @@ -172,7 +170,7 @@ func (c *QuayClient) newRequest(method, path string, body interface{}) (*http.Re } req, err := http.NewRequest(method, u.String(), buf) - if !utils.IsZeroOfUnderlyingType(c.AuthToken) { + if c.AuthToken != "" { req.Header.Set("Authorization", "Bearer "+c.AuthToken) } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 7235d338..bc711b5f 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -2,17 +2,12 @@ package utils import ( "fmt" - "reflect" "github.com/quay/quay-bridge-operator/pkg/constants" "github.com/quay/quay-bridge-operator/pkg/logging" corev1 "k8s.io/api/core/v1" ) -func IsZeroOfUnderlyingType(x interface{}) bool { - return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface()) -} - func RemoveItemsFromSlice(s []string, r []string) []string { for i, v := range s {