Skip to main content

StringTable

Struct StringTable 

Source
pub struct StringTable {
    pub count: u32,
    pub epoch: u64,
    /* private fields */
}
Expand description

interned strings of an arena

Fields§

§count: u32

number of strings

§epoch: u64

identity of the ids: changed when the ids change (see StringTable::compact)

Implementations§

Source§

impl StringTable

Source

pub fn memory_size(&self) -> usize

approximate number of bytes held by the table: the capacity of its vectors and the code units of the sources. reported to the javascript engine by the N-API addon, see crate::bindings::take_external_memory

Source

pub fn new() -> Self

Source

pub fn set_text(&mut self, source: usize, codes: CodeUnits)

set the code units of a source: the strings of the source are ranges of it. the buffer is shared, not copied

Source

pub fn release_codes(&mut self, _source: usize)

kept for parity with typescript: the code units are the text, there is nothing to release

Source

pub fn text(&self, source: usize) -> Option<&CodeUnits>

code units of a source

Source

pub fn intern(&mut self, str: &str) -> u32

intern a string

Source

pub fn intern_shared(&mut self, str: &SharedStr) -> u32

intern a shared string, without copying it intern a shared string: a shared Rc<str> is kept as is, a range of a source is copied

Source

pub fn intern_rc(&mut self, str: &Rc<str>) -> u32

Source

pub fn intern_units(&mut self, codes: &[u16]) -> u32

intern utf-16 code units (copied to the pool when they are not interned yet)

Source

pub fn intern_range( &mut self, codes: &CodeUnits, start: usize, end: usize, source: i32, ) -> u32

intern a range of the code units of a source (source >= 0, the range is kept) or of the canonical text (StringSource::Canonical, codes is the canonical text). use StringTable::intern_units for the pool

Source

pub fn intern_canonical(&mut self, start: u32, end: u32) -> u32

intern a range of the canonical text

Source

pub fn lookup(&self, str: &str) -> i32

id of a string, -1 when the string is not interned

Source

pub fn get(&mut self, id: u32) -> SharedStr

the string of an id. the string is created the first time it is read

Source

pub fn peek(&self, id: u32) -> String

the string of an id, without caching it

Source

pub fn with_str<R>(&self, id: u32, f: impl FnOnce(&str) -> R) -> R

run a function with the string of an id, without creating it when it is an ascii range of a source

Source

pub fn length(&self, id: u32) -> usize

length of a string, in utf-16 code units

Source

pub fn code_at(&self, id: u32, index: usize) -> u32

utf-16 code unit of a string

Source

pub fn with_units<R>(&self, id: u32, f: impl FnOnce(Units<'_>) -> R) -> R

the code units of a string, borrowed from where they are stored (the source text, the pool, the canonical text, the value): no copy

Source

pub fn copy_into(&self, id: u32, target: &mut Vec<u16>) -> usize

append the code units of a string to a buffer. the string is not created

Source

pub fn flag( &mut self, id: u32, flag: StringFlag, compute: impl FnOnce(&str) -> bool, ) -> bool

a boolean property of a string, computed once per id from the string

Source

pub fn cached(&self, id: u32) -> Option<SharedStr>

the string of an id when it has been created (cache[id])

Source

pub fn cached_flag(&self, id: u32, flag: StringFlag) -> Option<bool>

cached value of a flag, if it is computed

Source

pub fn set_flag(&mut self, id: u32, flag: StringFlag, value: bool)

store the value of a flag

Source

pub fn derived<T: Clone + 'static>( &self, id: u32, slot: StringDerived, ) -> Option<T>

a value derived from a string, if it is computed

Source

pub fn set_derived<T: 'static>( &mut self, id: u32, slot: StringDerived, value: T, )

store a value derived from a string

Source

pub fn copy_ascii(&self, id: u32, target: &mut Vec<u8>) -> isize

append the bytes of a string to a buffer when it is ascii. returns the number of bytes, -1 when the string is not ascii (nothing is appended)

Source

pub fn index_of_code(&self, id: u32, code: u32) -> isize

index of the first occurrence of a code unit, -1 when it is not found

Source

pub fn equals(&self, id: u32, str: &str) -> bool

true if the string of an id equals a string. the string is not created

Source

pub fn lower(&mut self, id: u32) -> u32

id of the lowercase string: the id itself when the string has no uppercase letter

Source

pub fn starts_with(&self, id: u32, str: &str) -> bool

true if the string of an id starts with a string

Source

pub fn equals_ignore_case(&self, id: u32, str: &str) -> bool

true if the string of an id equals a string, ignoring the case of the ascii letters

Source

pub fn compact(&mut self, used: &[u8]) -> Vec<u32>

drop the strings that are not used and renumber the others. returns the new id of each string

Source

pub fn export(&self) -> StringTableData

copy of the table

Source

pub fn import(&mut self, data: &StringTableData)

initialize the table from an exported copy

Trait Implementations§

Source§

impl Default for StringTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.