Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
78088: Revert "sql/schemachanger/screl: optimize walk a tad" r=postamar a=postamar

This reverts commit 9ac7585.

Fixes cockroachdb#78074.

Release justification: revert a problematic performance improvement
Release note: None

Co-authored-by: Marius Posta <[email protected]>
  • Loading branch information
craig[bot] and Marius Posta committed Mar 19, 2022
2 parents 4f361d3 + 5aa38f1 commit d84f07e
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions pkg/sql/schemachanger/screl/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ func walk(wantType reflect.Type, toWalk interface{}, f func(interface{}) error)
}
case reflect.Struct:
for i := 0; i < value.NumField(); i++ {
f := value.Field(i)
if !f.CanAddr() || !fieldIsExported(value.Type(), i) {
continue
if f := value.Field(i); f.CanAddr() && value.Type().Field(i).IsExported() {
walk(f.Addr().Elem())
}
walk(value.Field(i).Addr().Elem())
}
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
Expand All @@ -125,22 +123,3 @@ func walk(wantType reflect.Type, toWalk interface{}, f func(interface{}) error)
walk(v.Elem())
return nil
}

// fieldIsExported caches whether a field is exported as an optimization to avoid
// allocations due to (*reflect.Type).Field() calls.
func fieldIsExported(typ reflect.Type, field int) bool {
k := fieldExportedCacheKey{typ: typ, field: field}
if exported, ok := fieldExportedCache[k]; ok {
return exported
}
exported := typ.Field(field).IsExported()
fieldExportedCache[k] = exported
return exported
}

type fieldExportedCacheKey struct {
typ reflect.Type
field int
}

var fieldExportedCache = map[fieldExportedCacheKey]bool{}

0 comments on commit d84f07e

Please sign in to comment.