MCPcopy Create free account
hub / github.com/dolthub/doltgresql / UnsafeConvertStringToBytes

Function UnsafeConvertStringToBytes

postgres/parser/encoding/encoding.go:452–465  ·  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

450// modified if the input string is expected to be used again - doing so could
451// violate Go semantics.
452func UnsafeConvertStringToBytes(s string) []byte {
453 if len(s) == 0 {
454 return nil
455 }
456 // We unsafely convert the string to a []byte to avoid the
457 // usual allocation when converting to a []byte. This is
458 // kosher because we know that EncodeBytes{,Descending} does
459 // not keep a reference to the value it encodes. The first
460 // step is getting access to the string internals.
461 data := unsafe.StringData(s)
462 // Next we treat the string data as a maximally sized array which we
463 // slice. This usage is safe because the pointer value remains in the string.
464 return (*[0x7fffffff]byte)(unsafe.Pointer(data))[:len(s):len(s)]
465}
466
467// EncodeStringAscending encodes the string value using an escape-based encoding. See
468// EncodeBytes for details. The encoded bytes are append to the supplied buffer

Calls

no outgoing calls

Tested by

no test coverage detected