@@ -418,132 +418,311 @@ func Inline(val zapcore.ObjectMarshaler) Field {
418
418
// them. To minimize surprises, []byte values are treated as binary blobs, byte
419
419
// values are treated as uint8, and runes are always treated as integers.
420
420
func Any (key string , value interface {}) Field {
421
+ // To work around go compiler assigning unreasonably large space on stack
422
+ // (4kb, one `Field` per arm of the switch statement) which can trigger
423
+ // performance degradation if `Any` is used in a brand new goroutine.
424
+ var (
425
+ t zapcore.FieldType
426
+ i int64
427
+ s string
428
+ iface any
429
+ )
421
430
switch val := value .(type ) {
422
431
case zapcore.ObjectMarshaler :
423
- return Object (key , val )
432
+ t = zapcore .ObjectMarshalerType
433
+ iface = val
424
434
case zapcore.ArrayMarshaler :
425
- return Array (key , val )
435
+ t = zapcore .ArrayMarshalerType
436
+ iface = val
426
437
case bool :
427
- return Bool (key , val )
438
+ var ival int64
439
+ if val {
440
+ ival = 1
441
+ }
442
+ t = zapcore .BoolType
443
+ i = ival
428
444
case * bool :
429
- return Boolp (key , val )
445
+ if val == nil {
446
+ t = zapcore .ReflectType
447
+ break
448
+ }
449
+ var ival int64
450
+ if * val {
451
+ ival = 1
452
+ }
453
+ t = zapcore .BoolType
454
+ i = ival
430
455
case []bool :
431
- return Bools (key , val )
456
+ t = zapcore .ArrayMarshalerType
457
+ iface = bools (val )
432
458
case complex128 :
433
- return Complex128 (key , val )
459
+ t = zapcore .Complex128Type
460
+ iface = val
434
461
case * complex128 :
435
- return Complex128p (key , val )
462
+ if val == nil {
463
+ t = zapcore .ReflectType
464
+ break
465
+ }
466
+ t = zapcore .Complex128Type
467
+ iface = * val
436
468
case []complex128 :
437
- return Complex128s (key , val )
469
+ t = zapcore .ArrayMarshalerType
470
+ iface = complex128s (val )
438
471
case complex64 :
439
- return Complex64 (key , val )
472
+ t = zapcore .Complex64Type
473
+ iface = val
440
474
case * complex64 :
441
- return Complex64p (key , val )
475
+ if val == nil {
476
+ t = zapcore .ReflectType
477
+ break
478
+ }
479
+ t = zapcore .Complex64Type
480
+ iface = * val
442
481
case []complex64 :
443
- return Complex64s (key , val )
482
+ t = zapcore .ArrayMarshalerType
483
+ iface = complex64s (val )
444
484
case float64 :
445
- return Float64 (key , val )
485
+ t = zapcore .Float64Type
486
+ i = int64 (math .Float64bits (val ))
446
487
case * float64 :
447
- return Float64p (key , val )
488
+ if val == nil {
489
+ t = zapcore .ReflectType
490
+ break
491
+ }
492
+ t = zapcore .Float64Type
493
+ i = int64 (math .Float64bits (* val ))
448
494
case []float64 :
449
- return Float64s (key , val )
495
+ t = zapcore .ArrayMarshalerType
496
+ iface = float64s (val )
450
497
case float32 :
451
- return Float32 (key , val )
498
+ t = zapcore .Float32Type
499
+ i = int64 (math .Float32bits (val ))
452
500
case * float32 :
453
- return Float32p (key , val )
501
+ if val == nil {
502
+ t = zapcore .ReflectType
503
+ break
504
+ }
505
+ t = zapcore .Float32Type
506
+ i = int64 (math .Float32bits (* val ))
454
507
case []float32 :
455
- return Float32s (key , val )
508
+ t = zapcore .ArrayMarshalerType
509
+ iface = float32s (val )
456
510
case int :
457
- return Int (key , val )
511
+ t = zapcore .Int64Type
512
+ i = int64 (val )
458
513
case * int :
459
- return Intp (key , val )
514
+ if val == nil {
515
+ t = zapcore .ReflectType
516
+ break
517
+ }
518
+ t = zapcore .Int64Type
519
+ i = int64 (* val )
460
520
case []int :
461
- return Ints (key , val )
521
+ t = zapcore .ArrayMarshalerType
522
+ iface = ints (val )
462
523
case int64 :
463
- return Int64 (key , val )
524
+ t = zapcore .Int64Type
525
+ i = val
464
526
case * int64 :
465
- return Int64p (key , val )
527
+ if val == nil {
528
+ t = zapcore .ReflectType
529
+ break
530
+ }
531
+ t = zapcore .Int64Type
532
+ i = * val
466
533
case []int64 :
467
- return Int64s (key , val )
534
+ t = zapcore .ArrayMarshalerType
535
+ iface = int64s (val )
468
536
case int32 :
469
- return Int32 (key , val )
537
+ t = zapcore .Int32Type
538
+ i = int64 (val )
470
539
case * int32 :
471
- return Int32p (key , val )
540
+ if val == nil {
541
+ t = zapcore .ReflectType
542
+ break
543
+ }
544
+ t = zapcore .Int32Type
545
+ i = int64 (* val )
472
546
case []int32 :
473
- return Int32s (key , val )
547
+ t = zapcore .ArrayMarshalerType
548
+ iface = int32s (val )
474
549
case int16 :
475
- return Int16 (key , val )
550
+ t = zapcore .Int16Type
551
+ i = int64 (val )
476
552
case * int16 :
477
- return Int16p (key , val )
553
+ if val == nil {
554
+ t = zapcore .ReflectType
555
+ break
556
+ }
557
+ t = zapcore .Int16Type
558
+ i = int64 (* val )
478
559
case []int16 :
479
- return Int16s (key , val )
560
+ t = zapcore .ArrayMarshalerType
561
+ iface = int16s (val )
480
562
case int8 :
481
- return Int8 (key , val )
563
+ t = zapcore .Int8Type
564
+ i = int64 (val )
482
565
case * int8 :
483
- return Int8p (key , val )
566
+ if val == nil {
567
+ t = zapcore .ReflectType
568
+ break
569
+ }
570
+ t = zapcore .Int8Type
571
+ i = int64 (* val )
484
572
case []int8 :
485
- return Int8s (key , val )
573
+ t = zapcore .ArrayMarshalerType
574
+ iface = int8s (val )
486
575
case string :
487
- return String (key , val )
576
+ t = zapcore .StringType
577
+ s = val
488
578
case * string :
489
- return Stringp (key , val )
579
+ if val == nil {
580
+ t = zapcore .ReflectType
581
+ break
582
+ }
583
+ t = zapcore .StringType
584
+ s = * val
490
585
case []string :
491
- return Strings (key , val )
586
+ t = zapcore .ArrayMarshalerType
587
+ iface = stringArray (val )
492
588
case uint :
493
- return Uint (key , val )
589
+ t = zapcore .Uint64Type
590
+ i = int64 (val )
494
591
case * uint :
495
- return Uintp (key , val )
592
+ if val == nil {
593
+ t = zapcore .ReflectType
594
+ break
595
+ }
596
+ t = zapcore .Uint64Type
597
+ i = int64 (* val )
496
598
case []uint :
497
- return Uints (key , val )
599
+ t = zapcore .ArrayMarshalerType
600
+ iface = uints (val )
498
601
case uint64 :
499
- return Uint64 (key , val )
602
+ t = zapcore .Uint64Type
603
+ i = int64 (val )
500
604
case * uint64 :
501
- return Uint64p (key , val )
605
+ if val == nil {
606
+ t = zapcore .ReflectType
607
+ break
608
+ }
609
+ t = zapcore .Uint64Type
610
+ i = int64 (* val )
502
611
case []uint64 :
503
- return Uint64s (key , val )
612
+ t = zapcore .ArrayMarshalerType
613
+ iface = uint64s (val )
504
614
case uint32 :
505
- return Uint32 (key , val )
615
+ t = zapcore .Uint32Type
616
+ i = int64 (val )
506
617
case * uint32 :
507
- return Uint32p (key , val )
618
+ if val == nil {
619
+ t = zapcore .ReflectType
620
+ break
621
+ }
622
+ t = zapcore .Uint32Type
623
+ i = int64 (* val )
508
624
case []uint32 :
509
- return Uint32s (key , val )
625
+ t = zapcore .ArrayMarshalerType
626
+ iface = uint32s (val )
510
627
case uint16 :
511
- return Uint16 (key , val )
628
+ t = zapcore .Uint16Type
629
+ i = int64 (val )
512
630
case * uint16 :
513
- return Uint16p (key , val )
631
+ if val == nil {
632
+ t = zapcore .ReflectType
633
+ break
634
+ }
635
+ t = zapcore .Uint16Type
636
+ i = int64 (* val )
514
637
case []uint16 :
515
- return Uint16s (key , val )
638
+ t = zapcore .ArrayMarshalerType
639
+ iface = uint16s (val )
516
640
case uint8 :
517
- return Uint8 (key , val )
641
+ t = zapcore .Uint8Type
642
+ i = int64 (val )
518
643
case * uint8 :
519
- return Uint8p (key , val )
644
+ if val == nil {
645
+ t = zapcore .ReflectType
646
+ break
647
+ }
648
+ t = zapcore .Uint8Type
649
+ i = int64 (* val )
520
650
case []byte :
521
- return Binary (key , val )
651
+ t = zapcore .BinaryType
652
+ iface = val
522
653
case uintptr :
523
- return Uintptr (key , val )
654
+ t = zapcore .UintptrType
655
+ i = int64 (val )
524
656
case * uintptr :
525
- return Uintptrp (key , val )
657
+ if val == nil {
658
+ t = zapcore .ReflectType
659
+ break
660
+ }
661
+ t = zapcore .UintptrType
662
+ i = int64 (* val )
526
663
case []uintptr :
527
- return Uintptrs (key , val )
664
+ t = zapcore .ArrayMarshalerType
665
+ iface = uintptrs (val )
528
666
case time.Time :
529
- return Time (key , val )
667
+ if val .Before (_minTimeInt64 ) || val .After (_maxTimeInt64 ) {
668
+ t = zapcore .TimeFullType
669
+ iface = val
670
+ break
671
+ }
672
+ t = zapcore .TimeType
673
+ i = val .UnixNano ()
674
+ iface = val .Location ()
530
675
case * time.Time :
531
- return Timep (key , val )
676
+ if val == nil {
677
+ t = zapcore .ReflectType
678
+ break
679
+ }
680
+ if val .Before (_minTimeInt64 ) || val .After (_maxTimeInt64 ) {
681
+ t = zapcore .TimeFullType
682
+ iface = * val
683
+ break
684
+ }
685
+ t = zapcore .TimeType
686
+ i = val .UnixNano ()
687
+ iface = val .Location ()
532
688
case []time.Time :
533
- return Times (key , val )
689
+ t = zapcore .ArrayMarshalerType
690
+ iface = times (val )
534
691
case time.Duration :
535
- return Duration (key , val )
692
+ t = zapcore .DurationType
693
+ i = int64 (val )
536
694
case * time.Duration :
537
- return Durationp (key , val )
695
+ if val == nil {
696
+ t = zapcore .ReflectType
697
+ break
698
+ }
699
+ t = zapcore .DurationType
700
+ i = int64 (* val )
538
701
case []time.Duration :
539
- return Durations (key , val )
702
+ t = zapcore .ArrayMarshalerType
703
+ iface = durations (val )
540
704
case error :
541
- return NamedError (key , val )
705
+ if val == nil {
706
+ t = zapcore .SkipType
707
+ break
708
+ }
709
+ t = zapcore .ErrorType
710
+ iface = val
542
711
case []error :
543
- return Errors (key , val )
712
+ t = zapcore .ArrayMarshalerType
713
+ iface = errArray (val )
544
714
case fmt.Stringer :
545
- return Stringer (key , val )
715
+ t = zapcore .StringerType
716
+ iface = val
546
717
default :
547
- return Reflect (key , val )
718
+ t = zapcore .ReflectType
719
+ iface = val
720
+ }
721
+ return Field {
722
+ Key : key ,
723
+ Type : t ,
724
+ Integer : i ,
725
+ String : s ,
726
+ Interface : iface ,
548
727
}
549
728
}
0 commit comments