(t reflect.Type)
| 376 | } |
| 377 | |
| 378 | func typeEncoder(t reflect.Type) encoderFunc { |
| 379 | if fi, ok := encoderCache.Load(t); ok { |
| 380 | return fi.(encoderFunc) |
| 381 | } |
| 382 | |
| 383 | // To deal with recursive types, populate the map with an |
| 384 | // indirect func before we build it. This type waits on the |
| 385 | // real func (f) to be ready and then calls it. This indirect |
| 386 | // func is only used for recursive types. |
| 387 | var ( |
| 388 | wg sync.WaitGroup |
| 389 | f encoderFunc |
| 390 | ) |
| 391 | wg.Add(1) |
| 392 | fi, loaded := encoderCache.LoadOrStore(t, encoderFunc(func(e *encodeState, v reflect.Value, opts encOpts) { |
| 393 | wg.Wait() |
| 394 | f(e, v, opts) |
| 395 | })) |
| 396 | if loaded { |
| 397 | return fi.(encoderFunc) |
| 398 | } |
| 399 | |
| 400 | // Compute the real encoder and replace the indirect func with it. |
| 401 | f = newTypeEncoder(t, true) |
| 402 | wg.Done() |
| 403 | encoderCache.Store(t, f) |
| 404 | return f |
| 405 | } |
| 406 | |
| 407 | var ( |
| 408 | // SHIM(begin): TypeFor[T]() reflect.Type |
no test coverage detected
searching dependent graphs…