MCPcopy
hub / github.com/gofiber/fiber / GetString

Method GetString

app.go:801–809  ·  view source on GitHub ↗

GetString returns s unchanged when Immutable is off or s is read-only (rodata). Otherwise, it returns a detached copy (strings.Clone).

(s string)

Source from the content-addressed store, hash-verified

799// GetString returns s unchanged when Immutable is off or s is read-only (rodata).
800// Otherwise, it returns a detached copy (strings.Clone).
801func (app *App) GetString(s string) string {
802 if !app.config.Immutable || s == "" {
803 return s
804 }
805 if isReadOnly(unsafe.Pointer(unsafe.StringData(s))) { //nolint:gosec // pointer check avoids unnecessary copy
806 return s // literal / rodata → safe to return as-is
807 }
808 return strings.Clone(s) // heap-backed / aliased → detach
809}
810
811// GetBytes returns b unchanged when Immutable is off or b is read-only (rodata).
812// Otherwise, it returns a detached copy.

Callers 5

ParamsMethod · 0.45
Test_App_GetStringFunction · 0.45
Test_App_StateFunction · 0.45
TestState_GetStringFunction · 0.45
BenchmarkState_GetStringFunction · 0.45

Calls 1

isReadOnlyFunction · 0.70

Tested by 4

Test_App_GetStringFunction · 0.36
Test_App_StateFunction · 0.36
TestState_GetStringFunction · 0.36
BenchmarkState_GetStringFunction · 0.36