pub struct JsString { /* private fields */ }Expand description
An immutable string, stored on the GC heap.
The content is a Wtf8; the wrapper exists so a Value can hold a Gc handle rather
than the bytes.
Implementations§
Source§impl JsString
impl JsString
Sourcepub fn concat(
heap: &Heap,
left: &Gc<JsString>,
right: &Gc<JsString>,
) -> Option<JsString>
pub fn concat( heap: &Heap, left: &Gc<JsString>, right: &Gc<JsString>, ) -> Option<JsString>
Join two strings, flat or as a rope.
The policy is the reference’s, and its second half is what keeps the tree shallow:
when the left side is already a rope whose right child is short, the new text goes
into that child instead of growing the spine. A loop of appends therefore sits at
depth two, not at depth n.
None when the result would exceed JS_STRING_LEN_MAX, which is the reference’s
InternalError: string too long — the ceiling exists so a doubling loop stops
instead of overflowing.
Sourcepub fn units_cached(&self) -> Rc<Vec<u16>>
pub fn units_cached(&self) -> Rc<Vec<u16>>
The code units, decoding once and remembering the result.
Sourcepub fn code_unit_at(&self, index: usize) -> Option<u16>
pub fn code_unit_at(&self, index: usize) -> Option<u16>
The code unit at index, in O(1) once the cache is warm.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
The text with unpaired surrogates replaced by U+FFFD.
Trait Implementations§
Source§impl Trace for JsString
impl Trace for JsString
Source§fn external_bytes(&self) -> usize
fn external_bytes(&self) -> usize
The encoded bytes, plus the u16 cache once it has been built.
The cache counts because it is not free: s.charCodeAt(i) over a long string builds
one Rc<Vec<u16>> of twice the byte length, and a script can make thousands of such
strings. Reporting only the bytes would let a --memory-limit run reach twice the
limit it asked for.