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

Function UnsafeConvertStringToBytes

pkg/util/encoding/encoding.go:677–690  ·  view source on GitHub ↗

UnsafeConvertStringToBytes converts a string to a byte array to be used with string encoding functions. Note that the output byte array should not be modified if the input string is expected to be used again - doing so could violate Go semantics.

(s string)

Source from the content-addressed store, hash-verified

675// modified if the input string is expected to be used again - doing so could
676// violate Go semantics.
677func UnsafeConvertStringToBytes(s string) []byte {
678 if len(s) == 0 {
679 return nil
680 }
681 // We unsafely convert the string to a []byte to avoid the
682 // usual allocation when converting to a []byte. This is
683 // kosher because we know that EncodeBytes{,Descending} does
684 // not keep a reference to the value it encodes. The first
685 // step is getting access to the string internals.
686 hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
687 // Next we treat the string data as a maximally sized array which we
688 // slice. This usage is safe because the pointer value remains in the string.
689 return (*[0x7fffffff]byte)(unsafe.Pointer(hdr.Data))[:len(s):len(s)]
690}
691
692// EncodeStringAscending encodes the string value using an escape-based encoding. See
693// EncodeBytes for details. The encoded bytes are append to the supplied buffer

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…