fn as_owned(s: &str) -> String<'static>
Expand description
Creates an owned BString
from a borrowed string slice using a thread-local memory arena.
This function leverages the thread-local THR_ARENA
, which provides access to a memory allocator (Bump
) for efficient memory management.
It temporarily takes a reference to this allocator, and within an unsafe block, uses it to convert the input string slice into a BString
.
The allocator is dereferenced as a static lifetime to ensure it persists as long as necessary, allowing for the creation of a BString
that is not bound to the typical lifetime of the input slice.
This approach improves performance by reducing heap allocations for short-lived objects in multi-threaded scenarios.