Skip to content

Commit c03a31c

Browse files
committed
Small stylistic updates
1 parent 6805a3d commit c03a31c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

encode.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ func (enc *Encoder) eMap(key Key, rv reflect.Value, inline bool) {
423423

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

426+
func pointerTo(t reflect.Type) reflect.Type {
427+
if t.Kind() == reflect.Ptr {
428+
return pointerTo(t.Elem())
429+
}
430+
return t
431+
}
432+
426433
func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
427434
// Write keys for fields directly under this key first, because if we write
428435
// a field that creates a new table then all keys under it will be in that
@@ -435,18 +442,11 @@ func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
435442
rt = rv.Type()
436443
fieldsDirect, fieldsSub [][]int
437444
addFields func(rt reflect.Type, rv reflect.Value, start []int)
438-
ptrto func(t reflect.Type) reflect.Type
439445
)
440-
ptrto = func(t reflect.Type) reflect.Type {
441-
if t.Kind() == reflect.Ptr {
442-
return ptrto(t.Elem())
443-
}
444-
return t
445-
}
446446
addFields = func(rt reflect.Type, rv reflect.Value, start []int) {
447447
for i := 0; i < rt.NumField(); i++ {
448448
f := rt.Field(i)
449-
isEmbed := f.Anonymous && ptrto(f.Type).Kind() == reflect.Struct
449+
isEmbed := f.Anonymous && pointerTo(f.Type).Kind() == reflect.Struct
450450
if f.PkgPath != "" && !isEmbed { /// Skip unexported fields.
451451
continue
452452
}
@@ -586,8 +586,7 @@ func tomlTypeOfGo(rv reflect.Value) tomlType {
586586
}
587587

588588
func isMarshaler(rv reflect.Value) bool {
589-
return rv.Type().Implements(marshalText) ||
590-
rv.Type().Implements(marshalToml)
589+
return rv.Type().Implements(marshalText) || rv.Type().Implements(marshalToml)
591590
}
592591

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

708+
// Resolve any level of pointers to the actual value (e.g. **string → string).
709709
func eindirect(v reflect.Value) reflect.Value {
710710
if v.Kind() != reflect.Ptr && v.Kind() != reflect.Interface {
711711
if isMarshaler(v) {
712712
return v
713713
}
714-
if v.CanAddr() {
714+
if v.CanAddr() { /// Special case for marshalers; see #358.
715715
if pv := v.Addr(); isMarshaler(pv) {
716716
return pv
717717
}

0 commit comments

Comments
 (0)