// cachedTypeFields caches the return of typeFields to avoid repeated work.
cachedTypeFields caches the return of typeFields to avoid repeated work.
// cachedTypeFields caches the return of typeFields to avoid repeated work .
func cachedTypeFields(t reflect.Type, cfg *Config) []field {
	m, _ := fieldCache.value.Load().(map[reflect.Type][]field)
	f := m[t]
	if f != nil {
		return f
	}
	f = typeFields(t, cfg)
	if f == nil {
		f = []field{}
	}
	fieldCache.mu.Lock()
	m, _ = fieldCache.value.Load().(map[reflect.Type][]field)
	newM := make(map[reflect.Type][]field, len(m)+1)
	for k, v := range m {
		newM[k] = v
	}
	newM[t] = f
	fieldCache.value.Store(newM)
	fieldCache.mu.Unlock()
	return f
}
func cachedTypeFields ( t reflect . Type , cfg * Config ) [ ] field { m , _ := fieldCache . value . Load ( ) . ( map [ reflect . Type ] [ ] field ) f := m [ t ] if f != nil { return f } f = typeFields ( t , cfg ) if f == nil { f = [ ] field { } } fieldCache . mu . Lock ( ) m , _ = fieldCache . value . Load ( ) . ( map [ reflect . Type ] [ ] field ) newM := make ( map [ reflect . Type ] [ ] field , len ( m ) + 1 ) for k , v := range m { newM [ k ] = v } newM [ t ] = f fieldCache . value . Store ( newM ) fieldCache . mu . Unlock ( ) return f }
cachedTypeFields caches the return of typeFields to avoid repeated work.
cachedTypeFields caches the return of typeFields to avoid repeated work .
// Compute fields without lock. // Might duplicate effort but won't hold other computations back.