EncodeStringDescending is the descending version of EncodeStringAscending.
(b []byte, s string)
| 737 | |
| 738 | // EncodeStringDescending is the descending version of EncodeStringAscending. |
| 739 | func EncodeStringDescending(b []byte, s string) []byte { |
| 740 | if len(s) == 0 { |
| 741 | return EncodeBytesDescending(b, nil) |
| 742 | } |
| 743 | // We unsafely convert the string to a []byte to avoid the |
| 744 | // usual allocation when converting to a []byte. This is |
| 745 | // kosher because we know that EncodeBytes{,Descending} does |
| 746 | // not keep a reference to the value it encodes. The first |
| 747 | // step is getting access to the string internals. |
| 748 | hdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) |
| 749 | // Next we treat the string data as a maximally sized array which we |
| 750 | // slice. This usage is safe because the pointer value remains in the string. |
| 751 | arg := (*[0x7fffffff]byte)(unsafe.Pointer(hdr.Data))[:len(s):len(s)] |
| 752 | return EncodeBytesDescending(b, arg) |
| 753 | } |
| 754 | |
| 755 | // unsafeString performs an unsafe conversion from a []byte to a string. The |
| 756 | // returned string will share the underlying memory with the []byte which thus |
nothing calls this directly
no test coverage detected
searching dependent graphs…