GetString returns s unchanged when Immutable is off or s is read-only (rodata). Otherwise, it returns a detached copy (strings.Clone).
(s string)
| 799 | // GetString returns s unchanged when Immutable is off or s is read-only (rodata). |
| 800 | // Otherwise, it returns a detached copy (strings.Clone). |
| 801 | func (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. |