Skip to content

Commit

Permalink
Add benchmark test and if-statement to prevent unnecessary reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten van der Heijden committed Sep 5, 2023
1 parent c3b317c commit 53907cf
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 32 deletions.
5 changes: 5 additions & 0 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func walkThroughObject(registry LinkRegistry, object any, result any) {
func InjectLinks(registry LinkRegistry, object any) []byte {
rawResponseJson, _ := json.Marshal(object)

// If the registry is empty, don't bother doing any reflection
if len(registry) == 0 {
return rawResponseJson
}

var resultObject any

switch ensureConcrete(reflect.ValueOf(object)).Kind() {
Expand Down
Loading

0 comments on commit 53907cf

Please sign in to comment.