Skip to content

Commit

Permalink
remove recursion in interface conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrre committed Aug 5, 2024
1 parent ad3c9cf commit c0c3441
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ func (c *Config) WriteTypeAndValue(w io.Writer, st *State, v reflect.Value) {
if c.checkValid(w, v) {
return
}
if c.checkInterface(w, st, v) {
return
}
v = c.convertInterface(v)
c.runCheckDepth(w, st, func(st *State) {
WriteString(w, "(")
c.WriteType(w, v.Type())
Expand Down Expand Up @@ -193,12 +191,11 @@ func (c *Config) checkValid(w io.Writer, v reflect.Value) bool {
return false
}

func (c *Config) checkInterface(w io.Writer, st *State, v reflect.Value) bool {
func (c *Config) convertInterface(v reflect.Value) reflect.Value {
if v.Kind() == reflect.Interface {
c.WriteTypeAndValue(w, st, v.Elem())
return true
return v.Elem()
}
return false
return v
}

func (c *Config) runCheckDepth(w io.Writer, st *State, f func(st *State)) {
Expand Down

0 comments on commit c0c3441

Please sign in to comment.