MCPcopy
hub / github.com/labstack/echo / stringToBytes

Function stringToBytes

context.go:34–39  ·  view source on GitHub ↗

stringToBytes returns a []byte view over s without copying, avoiding the allocation+copy of []byte(s) on the response write path (the zero-copy technique used by fasthttp/fiber). Contract — all of the following must hold at every call site: - The result is read-only: writing through it is undefined

(s string)

Source from the content-addressed store, hash-verified

32// concrete writer may be a wrapping ResponseWriter (e.g. gzip); such writers must copy, not alias.
33// - s must stay reachable for as long as the slice is used: the slice aliases s's backing array.
34func stringToBytes(s string) []byte {
35 if s == "" {
36 return nil
37 }
38 return unsafe.Slice(unsafe.StringData(s), len(s))
39}
40
41// jsonpOpen and jsonpClose are the constant byte wrappers for JSONP payloads, kept as package-level
42// slices to avoid allocating them on every JSONP response.

Callers 4

HTMLMethod · 0.85
StringMethod · 0.85
jsonPBlobMethod · 0.85
JSONPBlobMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…