MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / EncodeStringDescending

Function EncodeStringDescending

pkg/util/encoding/encoding.go:739–753  ·  view source on GitHub ↗

EncodeStringDescending is the descending version of EncodeStringAscending.

(b []byte, s string)

Source from the content-addressed store, hash-verified

737
738// EncodeStringDescending is the descending version of EncodeStringAscending.
739func 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

Callers

nothing calls this directly

Calls 1

EncodeBytesDescendingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…