Skip to content

Commit

Permalink
Small stylistic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Jun 25, 2022
1 parent 6805a3d commit c03a31c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ func (enc *Encoder) eMap(key Key, rv reflect.Value, inline bool) {

const is32Bit = (32 << (^uint(0) >> 63)) == 32

func pointerTo(t reflect.Type) reflect.Type {
if t.Kind() == reflect.Ptr {
return pointerTo(t.Elem())
}
return t
}

func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
// Write keys for fields directly under this key first, because if we write
// a field that creates a new table then all keys under it will be in that
Expand All @@ -435,18 +442,11 @@ func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
rt = rv.Type()
fieldsDirect, fieldsSub [][]int
addFields func(rt reflect.Type, rv reflect.Value, start []int)
ptrto func(t reflect.Type) reflect.Type
)
ptrto = func(t reflect.Type) reflect.Type {
if t.Kind() == reflect.Ptr {
return ptrto(t.Elem())
}
return t
}
addFields = func(rt reflect.Type, rv reflect.Value, start []int) {
for i := 0; i < rt.NumField(); i++ {
f := rt.Field(i)
isEmbed := f.Anonymous && ptrto(f.Type).Kind() == reflect.Struct
isEmbed := f.Anonymous && pointerTo(f.Type).Kind() == reflect.Struct
if f.PkgPath != "" && !isEmbed { /// Skip unexported fields.
continue
}
Expand Down Expand Up @@ -586,8 +586,7 @@ func tomlTypeOfGo(rv reflect.Value) tomlType {
}

func isMarshaler(rv reflect.Value) bool {
return rv.Type().Implements(marshalText) ||
rv.Type().Implements(marshalToml)
return rv.Type().Implements(marshalText) || rv.Type().Implements(marshalToml)
}

// isTableArray reports if all entries in the array or slice are a table.
Expand Down Expand Up @@ -706,12 +705,13 @@ func encPanic(err error) {
panic(tomlEncodeError{err})
}

// Resolve any level of pointers to the actual value (e.g. **string → string).
func eindirect(v reflect.Value) reflect.Value {
if v.Kind() != reflect.Ptr && v.Kind() != reflect.Interface {
if isMarshaler(v) {
return v
}
if v.CanAddr() {
if v.CanAddr() { /// Special case for marshalers; see #358.
if pv := v.Addr(); isMarshaler(pv) {
return pv
}
Expand Down

0 comments on commit c03a31c

Please sign in to comment.