MCPcopy Index your code
hub / github.com/segmentio/encoding / encodeMapStringStringSlice

Method encodeMapStringStringSlice

json/encode.go:586–665  ·  view source on GitHub ↗
(b []byte, p unsafe.Pointer)

Source from the content-addressed store, hash-verified

584}
585
586func (e encoder) encodeMapStringStringSlice(b []byte, p unsafe.Pointer) ([]byte, error) {
587 m := *(*map[string][]string)(p)
588 if m == nil {
589 return append(b, "null"...), nil
590 }
591
592 stringSize := unsafe.Sizeof("")
593
594 if (e.flags & SortMapKeys) == 0 {
595 // Optimized code path when the program does not need the map keys to be
596 // sorted.
597 b = append(b, '{')
598
599 if len(m) != 0 {
600 var err error
601 i := 0
602
603 for k, v := range m {
604 if i != 0 {
605 b = append(b, ',')
606 }
607
608 b, _ = e.encodeString(b, unsafe.Pointer(&k))
609 b = append(b, ':')
610
611 b, err = e.encodeSlice(b, unsafe.Pointer(&v), stringSize, sliceStringType, encoder.encodeString)
612 if err != nil {
613 return b, err
614 }
615
616 i++
617 }
618 }
619
620 b = append(b, '}')
621 return b, nil
622 }
623
624 s := mapslicePool.Get().(*mapslice)
625 if cap(s.elements) < len(m) {
626 s.elements = make([]element, 0, align(10, uintptr(len(m))))
627 }
628 for key, val := range m {
629 v := val
630 s.elements = append(s.elements, element{key: key, val: &v})
631 }
632 sort.Sort(s)
633
634 start := len(b)
635 var err error
636 b = append(b, '{')
637
638 for i, elem := range s.elements {
639 if i != 0 {
640 b = append(b, ',')
641 }
642
643 b, _ = e.encodeString(b, unsafe.Pointer(&elem.key))

Callers

nothing calls this directly

Calls 3

encodeStringMethod · 0.95
encodeSliceMethod · 0.95
alignFunction · 0.70

Tested by

no test coverage detected