Skip to content

Commit

Permalink
Minor simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jul 6, 2024
1 parent 224c0bc commit 7466a43
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions internal/reflectext/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ func Visit(visitor Visitor, v reflect.Value, flags VisitFlags) {

// Special case for reflect.Value.
if (flags&VisitReflectValues) != 0 && v.Type() == ReflectValueType {
rv := v.Interface().(reflect.Value)
Visit(visitor, rv, flags)
Visit(visitor, v.Interface().(reflect.Value), flags)
return
}

Expand Down Expand Up @@ -192,8 +191,6 @@ func Visit(visitor Visitor, v reflect.Value, flags VisitFlags) {
case reflect.Slice:
if visitor.VisitSlice(ctx, v) {
if (flags & VisitSliceLenToCap) != 0 {
// The wrapper provides access to items beyond the slice's
// length, up to its capacity.
v = MakeSlice(v.Type(), v.UnsafePointer(), v.Cap(), v.Cap())
}
for i := 0; i < v.Len(); i++ {
Expand All @@ -217,7 +214,6 @@ func Visit(visitor Visitor, v reflect.Value, flags VisitFlags) {
case reflect.Struct:
if visitor.VisitStruct(ctx, v) {
if (flags & VisitUnexportedFields) != 0 {
// The wrapper makes unexported fields available.
unrestricted := StructValueOf(v)
for i := 0; i < unrestricted.NumField(); i++ {
Visit(visitor, unrestricted.Field(i), flags)
Expand All @@ -234,9 +230,7 @@ func Visit(visitor Visitor, v reflect.Value, flags VisitFlags) {

case reflect.Func:
if visitor.VisitFunc(ctx, v) && !v.IsNil() && (flags&VisitClosures) != 0 {
// The wrapper makes closure vars available.
fv := FuncValueOf(v)
if closure, ok := fv.Closure(); ok {
if closure, ok := FuncValueOf(v).Closure(); ok {
Visit(visitor, closure, flags)
}
}
Expand Down

0 comments on commit 7466a43

Please sign in to comment.