Skip to content

Commit

Permalink
Don't call reflect.ValueOf(msg) twice
Browse files Browse the repository at this point in the history
Closes: #94 [via git-merge-pr]
  • Loading branch information
Jacalz authored and psanford committed Oct 24, 2023
1 parent 1bb058c commit 68dc344
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions wormhole/wormhole.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,11 @@ func (c *msgCollector) closeWithErr(err error) {
}

func (c *msgCollector) waitFor(msg collectable) error {
if reflect.ValueOf(msg).Kind() != reflect.Ptr {
msgValue := reflect.ValueOf(msg)
if msgValue.Kind() != reflect.Ptr {
return errors.New("you must pass waitFor a pointer to a struct")
}

sub := collectSubscription{
collectMsg: msg,
result: make(chan collectResult, 1),
Expand All @@ -354,7 +356,7 @@ func (c *msgCollector) waitFor(msg collectable) error {
return result.err
}

dst := reflect.ValueOf(msg).Elem()
dst := msgValue.Elem()
src := reflect.ValueOf(result.result).Elem()

dst.Set(src)
Expand Down

0 comments on commit 68dc344

Please sign in to comment.